You are on page 1of 2

13.

Print a table of numbers from 0 to 99 as shown on the right:

for i in range(0,10):
for j in range(0,10):
print(str(i*10+j).rjust(2), end='\t')
print()
14. Print the table of multiplication:

for i in range(2, 10):


print(' | '.join(f"{i}x{j}={i*j:2}" for j in range(1, 10)))

15. Print out the number of digits of an integer value:

def count_digits():
n = int(input("Enter a number: "))
digits = len(str(abs(n)))
print("Number of digits in the input number is:", digits)
count_digits()

16. Print out the greatest common divisor (gcd) of two integer namely 45 and 135.

import math
gcd = math.gcd(45, 135)
print(f"The greatest common divisor of 45 and 135 is {gcd}")

17. Print out the sum all the items in a list.

def sum_list_items(lst):
return sum(lst)
user_input = input("Enter numbers separated by a space: ")
user_list = list(map(int, user_input.split()))
print(sum_list_items(user_list))

18. Print out the largest values and its position within a list:

lst = list(map(int, input("Enter numbers separated by space: ").split()))


max_value = max(lst)
print(f"Largest value is {max_value} at position {lst.index(max_value)+1}")
19. Remove duplicates from a list and print out the remaining list.

numbers = input("Enter numbers separated by space: ")


unique_numbers = list(set(numbers.split()))
print("The list without duplicates is:", unique_numbers)
20. Remove even numbers from a list and print out the remaining list.

numbers = list(map(int, input("Enter numbers separated by a space: ").split()))


print([num for num in numbers if num % 2 != 0])

You might also like