Program 1: Write a program to enter name, class, roll number, and marks from user and
display them accordingly.
# Taking user inputs
name = input("Enter your name: ")
cls = input("Enter your class: ")
rollno = int(input("Enter your roll number: "))
marks = float(input("Enter your marks: "))
# Displaying the information in a sentence
print(f"Student {name} is in class {cls} with roll number {rollno}.")
print("The student has scored", marks,"marks")
Program 1 :
Program 2: Write a Program to get a number from user and check if number is odd or
even.
num = int(input("Enter a number: "))
# Checking if the number is even or odd
if num % 2 == 0:
print(num, "is an Even number.")
else:
print(num, "is an Odd number.")
Program 2:
Program 3: Write a program to implement basic calculator operations (+,-,*,/) on two
numbers using if else statement.
# Display menu
print("Select operation:")
print("1. Addition (+)")
print("2. Subtraction (-)")
print("3. Multiplication (*)")
print("4. Division (/)")
choice = int(input("Enter choice (1/2/3/4): "))
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
if choice == 1:
print("sum:", num1 + num2)
elif choice == 2:
print("difference:", num1 - num2)
elif choice == 3:
print("producr:", num1 * num2)
elif choice == '4':
if num2 != 0:
print("division:", num1 / num2)
else:
print("Error: Division by zero is not allowed.")
else:
print("Invalid choice! Please enter 1, 2, 3, or 4.")
Program 3:
Program 4: Write a program to ask marks from the user and find student grade based on
his marks using if,elif,else.
score = float(input("Enter your score: "))
if score >= 80:
grade = 'A'
elif score >= 70 and score < 80:
grade = 'B'
elif score >= 55 and score < 70:
grade = 'C'
elif score >= 40 and score< 55:
grade = 'D'
else:
grade = "fail"
# Display the result
print("Your grade is:”, grade)
Program 4:
Program 5: Write a program to generate sum of following three sequences using loop:
x = float(input("Enter the value of x: "))
n = int(input("Enter the value of n: "))
sum1 = sum2=1
sum3 = x
for i in range(1,n +1):
sum1 = sum1 + x**i
sum2 = sum2 + (-1)**i * (x**i)
sum3 = sum3 + (-1)**(i+1) * (x**i/i)
print("Sum of first is:", sum1)
print("Sum of 2nd series is:", sum2)
print("Sum of 3rd series is:", sum3)
Program 5:
Program 6: Write a program to find numbers in first n natural numbers which are divisible
by a given no m using a while loop
n = int(input("Enter the number for the range : "))
m = int(input("Enter the value of divisor: "))
i=1
print ("Elements under " ,n, " divided by ",m ,” are: ")
while i < n:
if i % m == 0:
print(i)
i = i+1
Program 6:
Program 7: Write a program to find & Print numbers under n divisible by m using a for
loop. Value of m and n will be entered by the user.
n = int (input("Enter the number for the range : "))
m = int (input("Enter the value of divisor: "))
print ("Elements under " ,n, " divided by ",m ,” are: ")
for i in range(1, n + 1):
if i % m == 0:
print(i)
Program 7:
Program 8: Write a Program to check if a given number is prime or not.
num = int(input("Enter a number: "))
if num <=1:
print(num, "is NOT a prime number.")
else:
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
print(num, "is NOT a prime number.")
break
else:
print(num, "is a Prime number.")
Program 8:
Program 9: Write a Program to calculate factorial of a number. Number is enetered by
the user.
num = int(input("Enter a number: "))
fact = 1
if num < 0:
print("Factorial is not defined for negative numbers.")
else:
for i in range(1, num + 1):
fact = fact * i
print("Factorial of", num, "is", fact)
Program 9:
Program 10 : Write a program to generate following:
Series 1: print every 3rd element upto n natural numbers.
Series 2 : print every 3rd element upto n natural numbers in reverse order.
Series 3 : reverse the series
n = int(input("Enter the stop point="))
print("Series 1=")
for i in range(1,n+1,3):
print(i,end=" ")
print("\nSeries 2=")
for i in range(n,0,-3):
print(i,end=" ")
print("\nSeries 2=")
for i in range(n,0,-1):
print(i,end=" ")
Program 10:
Program 11: Write a program in python to count the no of vowels and consonants in a
string. String will be entered by the user.
s1 = input("Enter a string: ")
s1 = [Link]()
vowels = "aeiou"
consonants = "bcdfghjklmnpqrstvwxyz"
vcount = ccount = 0
for char in s1:
if char in vowels:
vcount += 1
elif char in consonants:
ccount += 1
print("Count of vowels:", vcount)
print("Count of consonants:", ccount)
Program 11:
PROGRAM 12: Write a program in python to count uppercase and lowercase letters in a
given string. String will be entered by the user.
# Get input from the user
s1 = input("Enter a string: ")
ucount=lcount=0
for i in s1:
if [Link]():
ucount += 1
elif [Link]():
lcount += 1
# Display the results
print("Count of Uppercase letters:", ucount)
print("Count of Lowercase letters:", lcount)
Program 12:
PROGRAM 13: Write a program to create a list of n elements from user input and then
search for a given element in the list.
n = int(input("Enter the no of items in the list: "))
mylist=[]
for i in range(n):
i=input('Enter the item:')
[Link](i)
print("My List of items is:")
for i in mylist:
print(i)
search_item = input("Enter the item to search for: ")
if search_item in mylist:
print("The item is found in the list.")
else:
print("The item is not found in the list.")
Program 13:
PROGRAM 14: Write a program to find the n of items, largest and smallest item in a
given list.
mylist=[10,12,8,30,9,78,90]
length = len(mylist)
maxvalue = max(mylist)
minvalue = min(mylist)
print("no of items in the list are:",length)
print("maximum item in the list is:",maxvalue)
print("minimum item in the list is:",minvalue)
Program 14:
Program 15 : Write a program to display all the words starting with a vowel in a given
string
text = input("Enter a string: ")
#convert the string into a list of words
wordlist = [Link]()
vowels = "AEIOUaeiou"
print("Words starting with vowels are:")
# Looping through each word
for i in wordlist:
if i[0] in vowels:
print(i)
Program 15:
Program 16: Write a program to display and count words in a tuple whose length is more
than 4.
mytuple = ("Apple","Pear","Peach","Mango","Pineapple")
count=0
# Looping through each word
for i in mytuple:
if len(i) > 4:
count+=1
print(i)
print("total words with length more than 4 :",count)
Program 16:
Program 17: Write a program to create a dictionary which maintains records of multiple
students. Student info is stored in rollno: name format. Search the dictionary and display
the students info whose name start with a.
n = int(input("Enter the number of students: "))
student = {}
for i in range(n):
rno = input("Enter Roll Number: ")
name = input("Enter Name: ")
student[rno] = name
print('Student whose name start with a/A:')
for i in student:
if student[i][0] in 'aA':
print(i,student[i],sep="----")
Program 17:
Program 18: Write a program that traverses a dictionary student. Student info is stored in
name: marks format. Ask the user name of the student to be modified and If the student
doesn’t exist display an error message.
student = {"Ram":87,"Ajay":89,"Hitesh":67,"Garvit":90}
print("students info before:")
print(student)
name = input("Enter the student name to be updated: ")
marks = input("Enter the student marks =")
if name not in student:
print("student doent exist")
else:
student[name]=marks
print('student marks updated')
print("students infor after :")
print(student)
Program 18:
Program 19: Write a program that traverses a dictionary student. Student info is stored in
name: marks format. Ask the user name of the student to be deleted and If the student
doesn’t exist display an error message.
student = {"Ram":87,"Ajay":89,"Hitesh":67,"Garvit":90}
print("students info before:")
print(student)
name = input("Enter the student name to be deleted: ")
if name not in student:
print("student doent exist")
else:
s= [Link](name)
print('student deleted')
print("students infor after :")
print(student)
Program 19:
Program 20: Write a program to create a dictionary which maintains records of multiple
students. And stores student rollno,name,marks. and then print student names who have
more than 75 marks .
n = int(input("Enter the number of students: "))
student = {}
for i in range(n):
rno = input("Enter Roll Number: ")
name = input("Enter Name: ")
marks = int(input("Enter Marks: "))
student[rno] = {"Name": name, "Marks": marks}
print(student)
# Display names of students with marks > 75
print("Names of students with marks > 75:")
for i in [Link]():
if i["Marks"] > 75:
print(i["Name"])
Program 20: