Practice Programs
Q.1 Program to print Hello in Python
print("Hello")
Q. 2 Multiplication table of a number entered by
user num = int(input("Enter a number: ")) for i in
range(1, 11): print(num, "x", i, "=", num * i)
Q.3 From the given range by the user print all the even numbers
start = int(input("Enter start: "))
end = int(input("Enter end: "))
for i in range(start, end + 1): if
i % 2 == 0: print(i)
Q. 4 Reverse of a number num =
int(input("Enter a number: ")) rev =
0 while num > 0: digit = num % 10
rev = rev * 10 + digit
num //= 10 (to find the integer division(quotient))
print("Reverse:", rev)
Q. 5 Sum of the number from the given range entered by the user
start = int(input("Enter start: "))
end = int(input("Enter end: "))
total = 0 for i in range(start,
end + 1):
total += i (means:- total =total +i) print("Sum:", total)
Q. 6 Program to convert Celsius to Fahrenheit c =
float(input("Enter temperature in Celsius: ")) f =
(c * 9/5) + 32
print("Fahrenheit:", f)
Q. 8 Program to find positive, negative and zero number
num = int(input("Enter a number: ")) if num > 0:
print("Positive")
elif num < 0:
print("Negative")
else: print("Zero")
Q. 9 Program to find factorial of a
number num = int(input("Enter
number: ")) fact = 1 for i in range(1,
num + 1): fact *= i
print("Factorial:", fact)
Q. 10 Program to Create and traverse a List
L1 = ["apple", "banana", "cherry"]
for item in L1: print(item)
Q. 10 Program to perform all the operation on the list.
L1 = [10, 20, 30, 40]
[Link](50)
[Link](1, 15)
[Link](30)
[Link]() L1[0]
=5
print("Updated list:", L1)
Q. 11 Program to sort a list.
L1 = [12, 4, 56, 7, 23]
[Link]()
print("Sorted list:", L1)
Q. 12 Program to perform the use of break and continue statement.
for i in range(1, 11):
if i == 5:
continue
if i == 9:
break print(i)
Q. 13 Program to insert elements into a List.
lst = []
n = int(input("How many elements? "))
for i in range(n):
element = input("Enter element: ")
[Link](element)
print("Final List:", lst)
Q. 14 Program to input a string and display a slice based on start and end index given by the user.
numbers = [10, 20, 30, 40, 50, 60, 70] print(numbers[1:5])
# slice from index 1 to 4 print(numbers[:4]) # first 4
elements print(numbers[3:]) # from index 3 to end
print(numbers[-4:-1]) # negative slicing
Q. 15 Program to demonstrate indexing on a string entered by the user.
fruits = ["apple", " banana", "cherry", "mango"]
print("First item:", fruits[0]) print("Last item:",
fruits[-1]) print("Second item:", fruits[1])
Q. 16 Program to perform pop, remove and del functions
numbers = [10, 20, 30, 40, 50]
[Link](2) # removes element at index 2 (30)
[Link](40) # removes the value 40
del numbers[1] # deletes element at index 1 (20)
or del numbers[1:3] # output ;- 10,40,50
print(numbers[])