0% found this document useful (0 votes)
2 views15 pages

Class_9_Python Programs_AI_417

The document contains a series of Python programming exercises that cover various basic programming concepts. Each exercise includes an input prompt, the corresponding code, and an expected output example. Topics range from simple input/output operations to calculations, conditionals, loops, and basic data manipulation.

Uploaded by

commonidmk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views15 pages

Class_9_Python Programs_AI_417

The document contains a series of Python programming exercises that cover various basic programming concepts. Each exercise includes an input prompt, the corresponding code, and an expected output example. Topics range from simple input/output operations to calculations, conditionals, loops, and basic data manipulation.

Uploaded by

commonidmk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Write a python program that asks the user for his name and then
welcomes him. The output should look like this:
For Example:
Enter your name: Pratham
Hello Pratham

Input:-
name = input("Enter your name: ")
print("Hello", name)

Output:-
Enter your name: Pratham
Hello Pratham
2. Write a python program that prompts the user to enter two integers and
display the total on the screen.
Input:-
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
total = num1 + num2
print("Total =", total)

Output:-
Enter first number: 5
Enter second number: 7
Total = 12
3. Write a python program to count Vowels in String.
Input:-
text = input("Enter a string: ")
vowels = 0
for ch in text:
if ch in "AEIOUaeiou":
vowels += 1
print("Number of vowels =", vowels)

Output:-
Enter a string: Hello
Number of vowels = 2
4. Write a python program which accept principle, rate and time from user
and print the simple interest. The formula to calculate simple interest is:
simple interest = principle X rate X time / 100.
Input:-
p = float(input("Enter principal: "))
r = float(input("Enter rate: "))
t = float(input("Enter time: "))
si = (p * r * t) / 100
print("Simple Interest =", si)

Output:-
Enter principal: 1000
Enter rate: 5
Enter time: 2
Simple Interest = 100.0
5. Write a python program that prompts the user to enter number in two
variables and swap the contents of the variables.
Input:-
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
a, b = b, a
print("After swapping:")
print("First number =", a)
print("Second number =", b)

Output:-
Enter first number: 10
Enter second number: 20
After swapping:
First number = 20
Second number = 10
6. Write a python program that prompts the user to input the radius of a
circle and outputs the area and circumference of the circle. The formula
is
Area = pi X radius2
Circumference = 2 X pi X radius
Input:-
radius = float(input("Enter radius of circle: "))
pi = 3.14
area = pi * radius * radius
circumference = 2 * pi * radius
print("Area =", area)
print("Circumference =", circumference)

Output:-
Enter radius of circle: 7
Area = 153.86
Circumference = 43.96
7. Write a python program that prompts the user to input the length and
the width of a rectangle and outputs the area and circumference of the
rectangle. The formula is
Area = Length x Width
Circumference = 2 x ( Length + Width)
Input:-
length = float(input("Enter length: "))
width = float(input("Enter width: "))
area = length * width
circumference = 2 * (length + width)
print("Area =", area)
print("Circumference =", circumference)

Output:-
Enter length: 5
Enter width: 3
Area = 15.0
Circumference = 16.0
8. Write a python program to find Maximum and Minimum in List of
numbers.
Input:-
numbers = [10, 20, 5, 40, 15]
print("Numbers:", numbers)
print("Maximum =", max(numbers))
print("Minimum =", min(numbers))

Output:-
Numbers: [10, 20, 5, 40, 15]
Maximum = 40
Minimum = 5
9. Write a python python program to calculate BMI of a person.
(Hint: BMI = weight / (height × height) where height is in meters)

Input:-
weight = float(input("Enter weight in kg: "))
height = float(input("Enter height in meters: "))
bmi = weight / (height * height)
print("BMI =", bmi)

Output:-
Enter weight in kg: 60
Enter height in meters: 1.6
BMI = 23.4375
[Link] a python program to calculate electricity bill.
(Hint: ₹5/unit up to 100 units, then ₹8/unit)
For 100 units bill will be 100 X 5 =500
For 120 units bill will be 100 X 5 + 20 X 8 = 660
Input:-
units = int(input("Enter number of units: "))
if units <= 100:
bill = units * 5
else:
bill = (100 * 5) + ((units - 100) * 8)
print("Electricity Bill = ₹", bill)

Output:-
Enter number of units: 120
Electricity Bill = ₹ 660
[Link] a python program to assign grade based on marks.
(Hint: >=90 → A+, >=75 → A, >=60 → B, below 60-> C)
Input:-
marks = int(input("Enter marks: "))
if marks >= 90:
grade = "A+"
elif marks >= 75:
grade = "A"
elif marks >= 60:
grade = "B"
else:
grade = "C"
print("Grade =", grade)

Output:-
Enter marks: 82
Grade = A
[Link] a python program to check if a person is eligible to vote.
(Hint: Age ≥ 18 → Eligible)
Input:-
age = int(input("Enter your age: "))
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")

Output:-
Enter your age: 16
You are not eligible to vote.
[Link] a python program to print Reverse Digits of Number.
For Example: n=1234
Expected Output = 4321
Input:-
n = int(input("Enter a number: "))
rev = 0
while n > 0:
digit = n % 10
rev = rev * 10 + digit
n = n // 10
print("Reverse =", rev)

Output:-
Enter a number: 1234
Reverse = 4321
[Link] a python program to print the number as given below with while
loop:
0
1
2
3
4
Input:-
i=0
while i < 5:
print(i)
i=i+1

Output:-
0
1
2
3
4
[Link] a python program to check if a password is strong.
(Hint: Password length ≥ 8 → Strong)
Input:-
password = input("Enter password: ")
if len(password) >= 8:
print("Strong Password")
else:
print("Weak Password")

Output:-
Enter password: abcd1234
Strong Password

You might also like