Untitled Document-2
Untitled Document-2
Example Output
Enter your name: Vikas Chhabra Hello, Vikas Chhabra! Welcome to Python Programming.
Q2. Product of Two Numbers: Write a program to input two numbers from the user and
print
their product
# Program to calculate the product of two numbers
Example Output
Enter the first number: 8 Enter the second number: 5 The product of 8.0 and 5.0 is 40.0.
Q3 Simple Calculator: Create a program that takes two numbers and an operator (+, -, *, /)
as
input and performs the respective calculation
# Program for a simple calculator
Example Output
Enter the first number: 12
Enter the second number: 4
Enter an operator (+, -, *, /): /
The result of 12.0 / 4.0 is 3.0
Q4 Voting Eligibility: Write a program to input a person’s age and check if they are
eligible to
vote (age >= 18)
# Program to check voting eligibility
# Checking eligibility
if age >= 18:
print("You are eligible to vote!")
else:
print("Sorry, you are not eligible to vote yet.")
Example Output
Enter your age: 20 You are eligible to vote!
Enter your age: 16 Sorry, you are not eligible to vote yet.
Q5 Odd or Even: Write a program to check whether a given number is odd or even.
# Program to check if a number is odd or even
Example Output
Enter a number: 8 The number 8 is even.
Enter a number: 7 The number 7 is odd.
Q6. Greatest of Two Numbers: Write a program to input two numbers and print the
greater
Number.
# Program to find the greatest of two numbers
Example Output
Enter the first number: 15 Enter the second number: 10 The greater number is 15.0.
Enter the first number: 8 Enter the second number: 12 The greater number is 12.0.
Enter the first number: 7 Enter the second number: 7 Both numbers are equal.
Q7Pass or Fail: Create a program to input marks of a student. If the marks are 33 or more,
print
"Pass"; otherwise, print "Fail."
# Program to check if a student passes or fails
# Taking marks as input from the user
marks = float(input("Enter your marks: "))
Q8 Number Comparison: Write a program to input three numbers and find the largest
number
among them.
# Program to find the largest of three numbers
Example Output
Enter the first number: 10
Enter the second number: 5
Enter the third number: 8
The largest number is 10.0.
Q9Leap Year Check: Write a program to input a year and check whether it is a leap year
# Program to check if a year is a leap year
Example Output
Enter a year: 2024
2024 is a leap year.
Example Output
Enter your marks: 92
Your grade is: A
Q11. Area of a Circle: Write a program to input the radius of a circle and calculate its
area. Use
the formula:
Area=π×radius2
(Take π=3.14).
# Program to calculate the area of a circle
Q12 Area of a Rectangle: Write a program to input the length and breadth of a rectangle
and calculate its area.
# Program to calculate the area of a rectangle
Example Output
Enter the length of the rectangle: 8
Enter the breadth of the rectangle: 5
The area of the rectangle with length 8.0 and breadth 5.0 is 40.0.
Q13 Perimeter of a Rectangle: Write a program to input the length and breadth of a
rectangle
and calculate its perimeter.
Example Output
Enter the length of the rectangle: 10
Enter the breadth of the rectangle: 5
The perimeter of the rectangle with length 10.0 and breadth 5.0 is 30.0.
Q14 Average Calculation: Write a program to input three numbers and calculate their
average
# Program to calculate the average of three numbers
# Taking three numbers as input from the user
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))
Example Output
Enter the first number: 8
Enter the second number: 10
Enter the third number: 12
The average of 8.0, 10.0, and 12.0 is 10.0.
Q15 Eligibility for Rewards: A shop gives rewards if a customer spends more than ₹5000.
Write a program to take input of the amount spent and check if the customer is eligible
for rewards or not.
# Program to check eligibility for rewards
Example Output
Enter the amount spent by the customer: 6000
You are eligible for rewards!