1. Write a python program to print Hello, world!
Solution:
print (“Hello, world!”)
OR
x= “Hello, World!”
print(x)
Output:
Hello, world!
2. Write a python program to print your address details.
Solution
print (“My Address”)
print (“————–“)
print (“Eliza Begum”)
print (“Parbatia, New Colony”)
print (“Gariasi Path”)
print (“Dist: Tinsukia”)
print (“P.O. Tinsukia”)
print (“Pin: 786125”)
print(“Assam”)
Output:

3. Write a program in python to print the following string in the specific format.

Solution:
print(“Welcome”)
print (“\tto Python”)
print(“\t\tProgramming”)
print (“invented by “)
print (“\tGuido van Rossum”)
print (“in Netherlands”)
OR
print(“Welcome \n\t to Python \n\t\t Programming \n invented by \n\t Guido van Rossum \n in Netherlands”)
Output:

4. Write a program in python to add two numbers.
Solution:
num1 = 10
num2 = 15
result = num1 + num2
print(“Sum:”, result)
OR
num1=10
num2 =15
print (f”Sum: {num1+num2}”)
Output:
Sum: 25
OR
n1, n2 = 10.2, 15.4
sum=n1+n2
print (f”Sum of {n1} and {n2} is: {sum}”)
Output:
Sum of 10.2 and 15.4 is: 25.6
5. Write a program to store two integer values in two variables and using them calculate addition, subtraction, multiplication division.
Solution:
n1, n2=20,15
print (“Addition: “, n1+n2)
print (“Subtraction: “, n1-n2)
print (“Multiplication: “, n1*n2)
print (“Division: “, n1/n2)
OR
n1, n2=20,15
print (f”Addition:{n1+n2}”)
print (f”Subtraction:{n1-n2}”)
print (f”Multiplication:{n1*n2}”)
print (f”Division:{n1/n2}”)
Output:
Addition: 35
Subtraction: 5
Multiplication: 300
Division: 1.3333333333333333
6. Write a python program to print your name, city and state taking input from user.
Solution:
name=input(“Enter name: “)
city=input(“Enter city: “)
state=input(“Enter state: “)
print(“——————-“)
print(“Name: “,name)
print(“City: “,city)
print(“state: “,state)
OR
name=input(“Enter name: “)
city=input(“Enter city: “)
state=input(“Enter state: “)
print(“—————————-“)
print(f”Name: {name}”)
print(f”City: {city}”)
print(f”State: {state}”)
OR
name=input(“Enter name: “)
city=input(“Enter city: “)
state=input(“Enter state: “)
print(“—————————-“)
print(f”Name: {name} \nCity: {city} \nState: {state}”)
Output:
Enter name: Eliza Begum
Enter city: Tinsukia
Enter state: Assam
——————-
Name: Eliza Begum
City: Tinsukia
state: Assam
7. Write a python program to add two numbers with user input.
Solution:
n1=input (“Enter 1st number: “)
n2=input(“Enter 2nd number: “)
sum=int(n1)+int(n2)
print(f”Sum of {n1} and {n2}: {sum}”)
OR
n1=int(input(“Enter 1st number:”))
n2=int(input(“Enter 2nd number:”))
sum=n1+n2
print(f”Sum of {n1} and {n2}: {sum}”)
Output:
Enter 1st number: 4
Enter 2nd number: 6
Sum of 4 and 6: 10
8. Write a program in python to add two floating point numbers taking user input.
Solution:
n1=input(“Enter 1st number:”)
n2=input(“Enter 2nd number:”)
sum=float(n1)+float(n2)
print(f”Sum of {n1} and {n2}: {sum}”)
OR
n1=float(input(“Enter 1st number:”))
n2=float(input(“Enter 2nd number:”))
sum=n1+n2
print(f”Sum of {n1} and {n2}: {sum}”)
Output:
Enter 1st number: 12.5
Enter 2nd number: 45.3
Sum of 12.5 and 45.3: 57.8
9. Write a program in python to perform addition, subtraction, multiplication and division on two input numbers taking from user.
Solution:
n1=int(input(“Enter 1st number:”))
n2=int(input(“Enter 2nd number:”))
print(f”Addition: {n1+n2}”)
print(f”Subtraction: {n1-n2}”)
print(f”Multiplication: {n1*n2}”)
print(f”Division: {n1/n2}”)
Output:
Enter 1st Number: 56
Enter 2nd Number: 8
Addition: 64
Subtraction: 48
Multiplication: 448
Division: 7.0
10. Write a python program to print your name and city taking input from user at a time.
Solution:
name, city=input(“Enter name and city: “).split()
print(f”Name: {name}”)
print(f”City: {city}”)
Output:
Enter name and city: Eliza Tinsukia
Name: Eliza
City: Tinsukia
OR
fname, lname, city=input(“Enter full name and city: “).split()
print(f”Name: {fname} {lname} \nCity: {city}”)
Output:
Enter full name and city: Prince Chutia Tinsukia
Name: Prince Chutia
City: Tinsukia
11. Write a program in python to add two numbers taking input from user at a time.
Solution:
n1,n2=map(int,input(“Enter 2 numbers :”).split())
sum=n1+n2
print(f”Sum of {n1} and {n2}: {sum}”)
Output:
Enter 2 numbers: 6 4
Sum of 6 and 4: 10
12. Write a python program to add two floating point numbers taking input from user at a time.
Solution:
n1,n2=map(float, input(“Enter 2 numbers: “).split ())
sum=n1+n2
print(f”Sum of {n1} and {n2}: {sum}”)
Output:
Enter 2 numbers: 12.3 34.2
Sum of 12.3 and 34.2: 46.5
13. Write a python program to calculate the Square of a number.
Solution:
num=5
square=num*num
print(f”Square of {num} is {square}”)
OR
num=5
square=num**2
print(f”Square of {num} is {square}”)
Output:
Square of 5 is 25
OR
n=int(input (“Enter a number:”))
sqr=n**2
print(f”Square of {n} is {sqr}”)
Output:
Enter a number:4
Square of 4 is 16
14. Write a python program to calculate the Power of a number.
Solution:
base=5
exponent=4
result=base**exponent
print(result)
Output:
625
OR
base=float(input(“Enter the base: “))
exp=float(input(“Enter exponent: “))
result=base**exp
print(f”{base} raised to the power of {exp} is {result}”)
Output:
Enter the base: 3
Enter exponent: 4
3.0 raised to the power of 4.0 is 81.0
15. Write a python program to calculate the Square Root of a number.
Solution:
n= 25
sq_root=n**0.5
print (f”Square root of {n}: {sq_root}”)
Output:
Square root of 25: 5.0
OR
n=float(input(“Enter a number:“))
sq_root = n ** 0.5
print(f”Square root of {n}: {sq_root}”)
Output:
Enter a number: 16
Square root of 16.0: 4.0
Note: double-star operator, ** is used for exponentiation, where one number is raised to the power of another. Ex. 2**3 is 8
16. Write a program in Python to calculate the area of a triangle. Formula: A = 1/2 * b * h
Solution:
b=float(input(“Enter the base: ”))
h=float(input(“Enter the height: “))
A=1/2 * b * h
print(f”Area of the triangle: {A}”)
print(f”Area of the triangle: {A: .3f}”)
Output:
Enter the base: 4.5
Enter the height: 6.3
Area of triangle: 14.174999999999999
Area of triangle: 14.175
17. Write a Python program to find the area of a circle.
Formula: A = πr2, π=22/7
Solution:
r=float(input(“Enter the radius: “))
A = 22/7 * r**2
print(f”Area of the circle: {A}”)
print(f”Area of the circle: {A: .3f}”)
Output:
Enter the radius: 3
Area of the circle: 28.285714285714285
Area of the circle: 28.286
18. Write a program in python to find the volume of a sphere. Formula: V = 4/3 πr3 , π=22/7
Solution:
r=float(input(“Enter the radius: “))
V = 4/3 * 22/7 * r**3
print(f”Volume of the sphere: {V}”)
print(f”Volume of the sphere: {V:.3f}”)
Output:
Enter the radius: 6
Volume of the sphere: 905.1428571428572
volume of the sphere: 905.143
19. Write a python program to convert temperature in Celsius to Fahrenheit.
Formula: F = (C * 9/5) + 32
Solution:
C=float(input(“Enter Temperature in Celsius: “))
F = (C * 9/5) + 32
print(f”Temperature in Fahrenheit: {F}”)
Output:
Enter Temperature in Celsius : 98
Temperature in Fahrenheit : 208.4
20. Write a program in python to convert temperature in Fahrenheit to Celsius.
Formula: C = (F-32) * 5/9
Solution:
F=float(input(“Enter Temperature in Fahrenheit: “))
C = (F – 32) * 5/9
print(f”Temperature in Celsius: {C}”)
Output:
Enter Temperature in Fahrenheit : 208.4
Temperature in Celsius : 98.0
21. Write a Python program to find the Sum of First n Natural Numbers. Formula: Sum of n natural number = n*(n+1)/2
Solution:
n=int(input(“Enter a number: “))
sum = n*(n+1)/2
print(f”Sum of first {n} natural numbers: {sum}”)
Output:
Enter a number: 5
Sum of first 5 natural numbers: 15
22. Write a program in Python to print pay-slip using the following data.
Employee number is 100
Basic salary is 5000
DA must be calculated as 10% of basic
HRA must be calculated as 20% of basic
Total salary must be calculated as Basic+DA+HRA
Solution:
ENo=100
BS=5000
DA=BS*10/100
HRA=BS*20/100
Total=BS+DA+HRA
print(“Pay Slip”)
print(“********************”)
print(f”Employee Number: {ENo}”)
print(f”Basic salary: {BS}”)
print(f”DA: {DA}”)
print(f”HRA: {HRA}”)
print(f”Total Salary: {BS+DA+HRA}”)
Output:
Pay Slip
********************
Employee Number: 100
Basic salary: 5000
DA: 500.0
HRA: 1000.0
Total Salary: 6500.0
23. Write a python program to swap values of two variables.
Solution:
x = int (input (“Enter the value of x: “))
y = int (input (“Enter the value of y: “))
x,y=y,x
print(f”Value of x after swapping: {x}”)
print(f”Value of y after swapping: {y}”)
Output:
Enter value of x: 10
Enter value of y: 20
Value of x after swapping: 20
Value of y after swapping: 10
24. Write a program in python to calculate Simple Interest. Formula: SI = (P * T * R)/100
Solution:
P=int(input(“Enter principal amount: “))
T=int(input(“Enter time period: “))
R=int(input(“Enter rate of interest: “))
SI = (P * T * R) / 100
print(f”The Simple Interest is {SI}”)
Output:
Enter the principal amount: 4000
Enter the time period: 2
Enter the rate of interest: 4
The Simple Interest is 320.0
25. Write a Python program to check two numbers are equal or not.
Solution:
n1,n2=15,15
if(n1==n2):
print (“Numbers are equal”)
else:
print (“Numbers are not equal”)
Output:
Numbers are equal
OR
n1,n2=23,15
if n1==n2:
print (“Numbers are equal”)
else:
print (“Numbers are not equal”)
Output:
Numbers are not equal
26. Write a program in Python to accept two numbers and check whether they are equal or not.
Solution:
n1=int(input(“Enter 1st number: “))
n2=int(input(“Enter 2nd number: “))
if(n1==n2):
print(“Numbers are equal”)
else:
print(“numbers are not equal”)
Output-1:
Enter 1st number: 7
Enter 2nd number: 7
Numbers are equal
Output-2:
Enter 1st number: 7
Enter 2nd number: 10
Numbers are not equal
27. Write a program in Python to find the larger number among two numbers.
Solution:
n1,n2=15,24
if n1>n2:
print (f”Larger number is: {n1}”)
else:
print (f”Larger numberis: {n2}”)
Output:
Larger number is: 24
OR
n1=int (input (“Enter 1st number: “))
n2=int (input (“Enter 2nd number: “))
if n1>n2:
print (f”Larger number is: {n1}”)
else:
print (f”Larger numberis: {n2}”)
Output-1:
Enter 1st number: 23
Enter 2nd number: 12
Larger number is: 23
Output:2
Enter 1st number: 23
Enter 2nd number: 45
Larger number is: 45
28. Write a python program to check a number is even or odd.
Solution:
num=20
if num % 2 == 0:
print (f”{num} is even number”)
else:
print (f”{num} is odd number”)
Output:
20 is even number
OR
num=25
if num % 2 == 0:
print (f”{num} is even number”)
else:
print (f”{num} is odd number”)
Output:
25 is odd number
OR
num = int(input(“Enter a number: “))
if num % 2 == 0:
print (f”{num} is even number”)
else:
print (f”{num} is odd number”)
Output-1
Enter a number: 8
8 is even number
Output-2
Enter a number: 5
5 is odd number
29. Write a program in Python to check a year is leap year or not.
Solution:
year=2025
if year % 4 ==0:
print (f”{year} is leap year”)
else:
print (f”{year} is not a leap year”)
Output:
2025 is not a leap year
OR
year = int (input (“Enter a year: “))
if year % 4 ==0:
print (f”{year} is leap year”)
else:
print (f”{year} is not a leap year”)
Output-1:
Enter a year: 2020
2020 is leap year
Output-2
Enter a year: 1998
1998 is not a leap year
30. Write a program in python to find the largest number among three numbers.
Solution:
n1,n2,n3=23,12,56
if n1>n2 and n1>n3:
largest=n1
elif n2>n1 and n2>n3:
largest=n2
else:
largest=n3
print(f”Largest number is: {largest}”)
Output:
Largest number is: 56
OR
n1= int(input(“Enter 1st number: “))
n2= int(input(“Enter 2nd number: “))
n3= int(input(“Enter 3rd number: “))
if n1>n2 and n1>n3:
largest=n1
elif n2>n1 and n2>n3:
largest=n2
else:
largest=n3
print(f”Largest number is: {largest}”)
OR
n1= int(input(“Enter 1st number: “))
n2= int(input(“Enter 2nd number: “))
n3= int(input(“Enter 3rd number: “))
if n1>n2 and n1>n3:
print(f”Largest number is: {n1}”)
elif n2>n1 and n2>n3:
print(f”Largest number is: {n2}”)
else:
print(f”Largest number is: {n3}”)
Output:
Enter 1st number: 6
Enter 2nd number: 7
Enter 3rd number: 9
Largest number is: 9
31. Write a program in Python to input a number between 1 to 7 and print the corresponding day of a week (day name).
Solution:
n=int(input(‘Enter a number(1-7): ‘))
if n==1:
print(‘Sunday’)
elif n==2:
print(‘Monday’)
elif n==3:
print(‘Tuesday’)
elif n==4:
print(‘Wednesday’)
elif n==5:
print(‘Thursday’)
elif n==6:
print(‘Friday’)
elif n==7:
print(‘Saturday’)
else:
print(‘Invalid number’)
Output-1:
Enter a number: 5
Thursday
Output-2:
Enter a number: 9
Invalid number
32. Write a Python program to check if a number is Positive, Negative or zero.
Solution:
num = 12
if num > 0:
print(“Positive”)
elif num < 0:
print(“Negative”)
else:
print(“Zero”)
Output:
Positive
OR
num = float(input(“Enter a number: “))
if num > 0:
print(“Positive number”)
elif num < 0:
print(“Negative number “)
else:
print(“It is zero”)
Output-1:
Enter a number: 2
Positive number
Output-2
Enter a number: – 5
Negative number
Output-3
Enter a number: 0
It is zero
33. Write a python program to check a character is vowel or not.
Solution:
x = input(“Enter a character: “)
if x==’a’ or x==’A’:
print(f”{x} is a vowel”)
elif x==’e’ or x==’E’:
print(f”{x} is a vowel”)
elif x==’i’ or x==’I’:
print(f”{x} is a vowel”)
elif x==’o’ or x==’O’:
print(f”{x} is a vowel”)
elif x==’u’ or x==’U’:
print(f”{x} is a vowel”)
else:
print(f”{x} is not a vowel”)
OR
x=input(“Enter a character: “)
if x==’a’ or x==’e’ or x==’i’ or x==’o’ or x==’u’:
print(f”{x} is a vowel”)
elif x==’A’ or x==’E’ or x==’I’ or x==’O’ or x==’U’:
print(f”{x} is a vowel”)
else:
print(f”{x} is not a vowel”)
OR
x = input(“Enter a character: “)
if x==’A’ or x==’a’ or x==’E’ or x==’e’ or x==’I’ or x==’i’ or x==’O’ or x==’o’ or x==’U’ or x==’u’:
print(f”{x} is a vowel”)
else:
print(f”{x} is not a vowel”)
OR
x=input(“Enter a character: “)
if x in(‘a’,’e’,’i’,’o’,’u’):
print(f”{x} is a vowel”)
elif x in(‘A’,’E’,’I’,’O’,’U’):
print(f”{x} is a vowel”)
else:
print(f”{x} is not a vowel”)
Output-1:
Enter a character: U
U is a vowel
Output-2
Enter a character: r
r is not a vowel
34. Write a python program to check a character is alphabet or not.
Solution:
ch=input(“Enter a character: “)
if((ch>=’a’ and ch<=’z’) or (ch>=’A’ and ch<=’Z’)):
print(f”{ch} is an alphabet”)
else:
print(f”{ch} is not an alphabet”)
OR
ch=input(“Enter a character: “)
if ch>=’a’ and ch<=’z’:
print(f”{ch} is an alphabet”)
elif ch>=’A’ and ch<=’Z’:
print(f”{ch} is an alphabet”)
else:
print(f”{ch} is not an alphabet”)
Output-1:
Enter a character: G
G is an alphabet
Output-2:
Enter a character: /
/ is not an alphabet
35. Write a program to calculate total marks and percentage of a student of 5 subjects and based on the percentage display the grade according to the following criteria.
Below 30 D
30-44 C
45-54 B
55-64 B+
65-85 A
Above 85 A+
Solution:
print(“Enter the marks :-“)
eng=int(input(“English: “))
math=int(input(“Mathematics: “))
hindi=int(input(“Hindi: “))
sc=int(input(“Science: “))
geo=int(input(“Geography: “))
total=eng+math+hindi+sc+geo
per = (total/500*100)
print(f”Total marks: {total}”)
print(f”Percentage: {per}”)
if per<30:
print(“Grade: D”)
elif per<45:
print(“Grade: C”)
elif per<55:
print(“Grade: B”)
elif per<65):
print(“Grade: B+”)
elif per<=85):
print(“Grade: A”)
else:
print(“Grade: A+”)
Output:
Enter the marks:-
English: 78
Mathematics: 89
Hindi: 67
Science: 90
Geography: 85
Total marks: 409
Percentage: 81.8
Grade: A
OR
s1, s2, s3,s4,s5=map(int,input(“Enter marks of 5 subjects: “).split())
total = s1+s2+s3+s4+s5
per = (total/500*100)
print(f”Total marks: {total}”)
print(f”Percentage: {per}”)
if per<30:
print(“Grade: D”)
elif per<45:
print(“Grade: C”)
elif per<55:
print(“Grade: B”)
elif per<65):
print(“Grade: B+”)
elif per<=85:
print(“Grade: A”)
else:
print(“Grade: A+”)
Output:
Enter marks of 5 subjects of a student: 78 75 87 98 95
Total marks: 433
Percentage: 86.6
Grade: A+
36. Write a python program to make a Simple Calculator.
Solution:
n1=int(input(“Enter 1st Number: “))
n2=int(input (“Enter 2nd Number: “))
op=input(“Enter any of these operator (+,-,*,/): “)
if op== ‘+’:
result = n1 + n2
elif op== ‘-‘:
result = n1 – n2
elif op== ‘*’:
result = n1 * n2
elif op== ‘/’:
result = n1 / n2
else:
result=”Invalid Operator”
print (f”{n1} {op} {n2}: {result}”)
Output-1:
Enter 1st Number: 5
Enter 2nd Number: 9
Enter any of these operator (+,-,*,/): *
5 * 9: 45
Output-2:
Enter 1st Number: 4
Enter 2nd Number: 6
Enter any of these operator (+,-,*,/): #
4 # 6: Invalid Operator
37. Write a program to check if a number is Positive, Negative or zero using nested if statement.
Solution:
num = int(input(“Enter a number: “))
if num>=0:
if num==0:
print(“It is zero”)
else:
print(“Positive number”)
else:
print(“Negative number “)
Output-1
Enter a number: 0
It is zero
Output-2:
Enter a number: 2
Positive number
Output-3
Enter a number: – 5
Negative number
38. Write a program in Python simulating a traffic light using match case statement.
Solution:
color=input(“Enter the traffic light colour, r/R for red, y/Y for yellow, g/G for green: “)
match color:
case ‘r’|’R’:
print(“Traffic Light: RED – STOP”)
case ‘y’|’Y’:
print(“Traffic Light: YELLOW – Slow”)
case ‘g’|’G’:
print(“Traffic Light: GREEN – Go!”)
case _:
print(“Invalid input.”)
Output-1:
Enter the traffic light colour, r/R for red, y/Y for yellow, g/G for green: R
Traffic Light: RED – STOP
Output-2:
Enter the traffic light colour, r/R for red, y/Y for yellow, g/G for green: G
Traffic Light: GREEN – Go!
Output-3:
Enter the traffic light colour, r/R for red, y/Y for yellow, g/G for green: y
Traffic Light: YELLOW – Slow
Output-4:
Enter the traffic light colour, r/R for red, y/Y for yellow, g/G for green: B
Invalid input.
39. Write a Python program to categorize days of the week into weekdays or weekends using match case.
Solution:
day = input(“Enter a day of the week: “)
match day:
case “Monday” | “Tuesday” | “Wednesday”|”Thursday”|”Friday”:
print(f”{day} is a weekday.”)
case “Saturday”|”Sunday”:
print(f”{day} is a weekend.”)
case _:
print(“That’s not a valid day.”)
Output-1:
Enter a day of the week: Thursday
Thursday is a weekday.
Output-2:
Enter a day of the week: Sunday
Sunday is a weekend.
Output-3:
Enter a day of the week: Funday
That’s not a valid day of the week.
40. Write a python program to print individual characters of a string.
Solution:
name=’Eliza’
for x in name:
print(x)
Output:
E
L
I
Z
A
OR
for x in “ELIZA”:
print(x,end=’ ‘)
Output:
E L I Z A
OR, We can do the above program by taking input from user :
x=input (“Enter a string: “)
print(“Characters in the string:”)
for char in x:
print (char, end=’ ‘)
Output:
Enter a string: welcome
Characters in the string:
w e l c o m e
41. Write a program in python to print characters of “python”.
Solution:
for letter in ‘python’:
print(letter, end=’ ‘)
Output:
p y t h o n
42. Write a for loop to iterate through a string and write it in reverse.
Solution:
string = “welcome”
rev_str=’ ‘
for x in string:
rev_str = x + rev_str
print(f”Original string is: {string}”)
print(f”Reversed string is: {rev_str}”)
Output:
Original string is: welcome
Reversed string is: emoclew
OR
string = input(“Enter a string: “)
rev_str=’ ‘
for x in string:
rev_str = x + rev_str
print(f”Original string is: {string}”)
print(f”Reversed string is: {rev_str}”)
Output:
Enter a string: hello
Original string is: hello
Reversed string is: olleh
43. Write a for loop that prints the numbers from 1 to 10.
Solution:
numbers = [1,2,3,4,5,6,7,8,9,10]
for num in numbers:
print(num,end=’ ‘)
OR
for num in range(1,11):
print(num,end=’ ‘)
Output:
1 2 3 4 5 6 7 8 9 10
44. Write a program in Python program to print first 15 natural numbers.
Solution:
print (“First 15 natural numbers: “)
for i in range (1,16):
print (i, end=’ ‘)
Output:
First 15 natural numbers:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
45. Write a Python program to print series of numbers from 30 to 60.
Solution:
print(“Numbers from 30 to 60: “)
for i in range(30,61):
print(i,end=’ ‘)
Output:
Numbers from 30 to 60:
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
46. Write a program to print series of number from 100 to 50 in reversing order.
Solution:
for i in range(100,49,-1):
print(i,end=’ ‘)
Output:
100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50
47. Write a python program to print even numbers in a range.
Solution:
start = 2
stop = 20
print(f”Even numbers from {start} to {stop}:”)
for n in range(start, stop + 1):
if n % 2 == 0:
print(n,end=’ ‘)
Output:
Even numbers from 2 to 20:
2 4 6 8 10 12 14 16 18 20
OR
start = int(input(“Enter start range: “))
stop = int (input(“Enter end range: “))
print(f”Even numbers from {start} to {stop}:”)
for num in range(start, stop + 1):
if num % 2 == 0:
print(num,end=’ ‘)
Output:
Enter start range: 3
Enter end range: 23
Even numbers from 3 to 23:
4 6 8 10 12 14 16 18 20 22
48. Write a Python program to print odd numbers within a range.
Solution:
start = 1
stop = 10
print(f”Odd numbers from {start} to {stop}:”)
for n in range(start, stop+1):
if n % 2 != 0:
print(n,end=’ ‘)
Output:
Odd numbers from 1 to 10:
1 3 5 7 9
OR
start = int (input(“Enter start range: “))
stop = int (input(“Enter end range: “))
print(f”Odd numbers from {start} to {stop}:”)
for num in range(start, stop + 1):
if num % 2 != 0:
print(num,end=’ ‘)
Output:
Enter start range: 5
Enter end range: 15
Odd numbers from 5 to 15:
5 7 9 11 13 15
49. Write a program in python to print multiplication table for any number.
Solution:
num=int(input (“Enter a number: “))
print (“Multiplication table of”, num)
for i in range (1, 11):
print (f”{num} x {i} = {num*i}”)
Output:
Enter the number: 5
Multiplication Table of 5
5 x 1 = 5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
50. Write a python program to print multiplication table upto 5.
Solution:
print(“Multiplication table up to 5”)
for i in range(1, 6):
for j in range(1,11):
print (f”{i} x {j} = {i*j}”)
print()
Output:
1 x 1 = 1
1 x 2 = 2
1 x 3 = 3
1 x 4 = 4
1 x 5 = 5
1 x 6 = 6
1 x 7 = 7
1 x 8 = 8
1 x 9 = 9
1 x 10 = 10
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20
…………….
……………..
51. Write a python program to print the following pattern. (Right-Angled Triangle Pattern)

Solution:
n=int(input(“Enter no. of rows: “))
for i in range(n):
print(“* ” * (i+1))
Output:
Enter no. of rows: 5

52. Write a program in python to print the following pattern. (inverted right-angled triangle pattern)

Solution:
n=int(input(“Enter no. of rows: “))
for i in range(n):
print(“* ” * (n-i))
Output:
Enter no. of rows: 5

53. Write a program in python to print the following pattern.

Solution:
n=int(input(“Enter number of rows: “))
for i in range(n):
print(” ” * (n-i-1) + “* ” * (i+1))
Output:
Enter number of rows: 5

54. Write a program in python to print the following pattern.

Solution:
n=int(input(“Enter number of rows: “))
for i in range(n):
print(” ” * (n-i-1) + “* ” * (i+1))
Output:
Enter number of rows: 5

55. Write a program in python to print the following pattern.

Solution:
n=int(input(“Enter number of rows: “))
for i in range(n):
print(” ” * (n-i-1) + “* ” * (2*i+1))
Output:
Enter number of rows: 5

56. Write a program in python to print 10 to 20 using while loop.
OR
Write a python program to print a number series using while loop.
Solution:
print(“Numbers from 10 to 20…”)
n=10
while n<=20:
print(n, end=’ ‘)
n+=1
Output:
Numbers from 10 to 20…
10 11 12 13 14 15 16 17 18 19 20
57. Write a program in Python to print numbers until the user enters 0 (Enter zero to quit).
Solution:
n=int(input(“Enter a number: “))
while n!=0:
print(f”You entered {n}”)
n = int(input(“Enter a number: “))
print(“The end”)
Output:
Enter a number: 3
You entered 3
Enter a number: 6
You entered 6
Enter a number: 9
You entered 9
Enter a number: 0
The end
58. Write a program to accept only one character as input from the user in Python.
Solution:
while True:
user_input=input(“Enter a character: “)
if len(user_input) == 1:
print(f”You entered: {user_input}”)
break
else:
print(“Invalid input. Please enter one character.”)
Output:
Enter a character: eliza
Invalid input. Please enter one character.
Enter a character: bye
Invalid input. Please enter one character.
Enter a character: a
You entered: a
59. Write a python program to print elements in a list.
Solution:
fruits=[‘banana’, ‘apple’, ‘mango’, ‘orange’, ’grapes’]
print(“Elements in the list:”)
for x in fruits:
print(x)
Output:
Elements in the list:
banana
apple
mango
orange
grapes
OR
fruits=[‘banana’, ‘apple’, ‘mango’, ‘orange’, ’grapes’]
print(“Elements in the list:”)
for x in fruits:
print(x, end= ‘ ‘)
Output:
Elements in the list:
banana apple mango orange grapes
60. Write a for loop to iterate through a list and sum up the elements.
Solution:
numbers = [1, 2, 3, 4, 5]
sum = 0
for n in numbers:
sum += n
print(f”Sum of the elements: {sum}”)
Output:
Sum of the elements: 15
61. Write a Python program to print even numbers from a list.
Solution:
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(“Even numbers in the list:”)
for n in numbers:
if n % 2 == 0:
print(n,end=’ ‘)
Output:
Even numbers in the list:
2 4 6 8 10
62. Write a Python program to print odd numbers from a list.
Solution:
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(“Odd numbers in the list:”)
for n in numbers:
if n % 2 != 0:
print(n,end=’ ‘)
Output:
Odd numbers in the list:
1 3 5 7 9
63. Write a program in Python to reverse a string.
Solution:
string = “hello”
reverse=string[::-1]
print(f”Original string is: {string}”)
print(f”Reverse of {string} is: {reverse}”)
Output:
Original string: hello
Reverse of hello is: olleh
OR
string = input(“Enter an string: “)
reverse=string[::-1]
print(f”Reverse of {string} is: {reverse}”)
Output:
Enter a string: assam
Reverse of assam is: massa
64. Write a Python program to reverse a number.
Solution:
n = 3456
reverse=str(n)[::-1]
print(f”Original number: {n}”)
print(f”Reverse of {n} is: {reverse}”)
Output:
Original number: 3456
Reverse of 3456 is: 6543
OR
n = int(input(“Enter a number: “))
reverse=str(n)[::-1]
print(f”Original number: {n}”)
print(f”Reverse of {n} is: {reverse}”)
Output:
Enter a number: 1234
Original number: 1234
Reverse of 1234 is: 4321
65. Write a program in Python to reverse a list.
Solution:
my_list=[2,4,6,8,10]
reverse=my_list[::-1]
print(f”Original list is: {my_list}”)
print(f”Reversed list is: {reverse}”)
Output:
Original list is: [2, 4, 6, 8, 10]
Reversed list is: [10, 8, 6, 4, 2]
66. Write a python program to create an array contains six integers. Also print all the members of the array.
Solution:
import array
my_array=array. array (‘i’, [10,20,30,40,50,60])
print (“Elements of the given array: “);
for i in my_array:
print (i, end=’ ‘)
OR
import array as a
my_array=a. array (‘i’, [10,20,30,40,50])
print (“Elements of the given array: “);
for i in my_array:
print (i, end=’ ‘)
OR
from array import *
my_array=array (‘i’, [10,20,30,40,50,60])
print (“Elements of the given array: “);
for i in my_array:
print (i, end=’ ‘)
Output:
Elements of given array:
10 20 30 40 50 60
67. Write a python program to reverse the order of the array items.
Solution:
from array import*
my_array=array(‘i’,[10,20,30,40,50])
print(“Original Array: “)
for i in my_array:
print(i,end=’ ‘)
print(“\n\nReversed Array: “)
my_array.reverse()
for i in my_array:
print(i,end=’ ‘)
Output:
Original Array:
10 20 30 40 50
Reversed Array:
50 40 30 20 10
68. Write a python program to add two positive integers without using the ‘+’ operator.
Solution:
result=sum([10,5])
print(f”Sum of two numbers: {result}”)
Output:
Sum of two numbers: 15
OR
n1,n2=10,5
result=sum([n1,n2])
print(f”Sum of {n1} and {n2} is: {result}”)
Output:
Sum of 10 and 5 is: 15
OR
n1=int (input (“Enter 1st number: “))
n2=int (input (“Enter 2nd number: “))
result=sum ([n1, n2])
print(f”Sum of {n1} and {n2} is: {result}”)
Output:
Enter 1st number: 20
Enter 1st number: 30
Sum of 20 and 30 is 50
69. Write a python program to print your address details using function.
Solution:
def address ():
name = “Priya Sharma”
city = “Tinsukia”
dist = “Tinsukia”
state = “Assam”
pin = 786125
print(f”Name: {name}”)
print(f”City: {city}”)
print(f”Dist: {dist}”)
print(f”State: {state}”)
print(f”Pin: {pin}”)
print(“My Address”)
print(“—————–“)
address()
Output:
My Address
—————–
Name: Priya Sharma
City: Tinsukia
Dist: Tinsukia
State: Assam
Pin: 786125
70. Write a program to add two numbers in python using function.
Solution:
def add_num():
n1,n2=5,10
result=n1+n2
print(“Sum: “,result)
add_num()
OR
def add_num (a, b):
return a + b
sum= add_num (5,10)
print (“Sum: “, sum)
Output:
Sum: 15
70. Write a program to find maximum of two numbers using function.
Solution:
def maximum(a, b):
if a >= b:
return a
else:
return b
print(“Maximum Number: “,maximum(2, 7))
Output:
Maximum Number: 7
Method 2: Using inbuilt max() Function
a=int(input(“Enter 1st number: “))
b=int(input(“Enter 2nd number: “))
print(“Maximum number is”, max(a,b))
Output:
Enter 1st number: 4
Enter 2nd number: 3
I truly admired the work you’ve put in here. The design is refined, your authored material stylish, however, you seem to have acquired some trepidation about what you intend to present next. Undoubtedly, I’ll revisit more regularly, similar to I have nearly all the time, in the event you sustain this rise.
Thanks a lot for your comment.
This website has quickly become my go-to source for [topic]. The content is consistently top-notch, covering diverse angles with clarity and expertise. I’m constantly recommending it to colleagues and friends. Keep inspiring us!
Thank you for your kind words. Thanks a lot for recommending my site…
What a fantastic resource! The articles are meticulously crafted, offering a perfect balance of depth and accessibility. I always walk away having gained new understanding. My sincere appreciation to the team behind this outstanding website.
Thank you!!!
Thank you for your response! I’m grateful for your willingness to engage in discussions. If there’s anything specific you’d like to explore or if you have any questions, please feel free to share them. Whether it’s about emerging trends in technology, recent breakthroughs in science, intriguing literary analyses, or any other topic, I’m here to assist you. Just let me know how I can be of help, and I’ll do my best to provide valuable insights and information!
Thank you so much…
Hiya, I’m really glad I’ve found this info. Nowadays bloggers publish just about gossips and internet and this is actually frustrating. A good site with exciting content, that is what I need. Thank you for keeping this web site, I will be visiting it. Do you do newsletters? Can not find it.