CBSE Python(083) Class 12 Python Revision 1 Unsolved programs 2023–24
--
- Write a program to print one of the words negative, Zero, or positive, according to whether variable x is less than zero, zero, or greater than zero respectively?
2. Write a program that returns True if the input number is an even number, False otherwise.
3. Write a python program that calculates and prints the number of seconds in a year.
4. Write a python program that accepts two integers from the user and prints a message saying if first number is divisible by second number or if it is not.
5. Write a program that asks the user number in a year in the range 2 to 365 and asks the first day of the year — Sunday or Monday or Tuesday etc., Then the program should display the day on the day -number that has been input.
6. One foot equals to 12 inches. Write a function that accepts a length written in feet as an argument and returns this length written in inches. Write a second function that asks the user for a number of feet and returns this value. Write a third function that accepts a number of inches and displays this to the screen. Use these three functions to write a program that asks the user for a number of feet and tells them the corresponding number of inches.
7. Write a program that reads an integer N from the keyboard computers and displays the sum of the numbers from N to (2*N) if N non negative. If N in a negative number, then its the sum of numbers from (2*N) to N. The starting and ending points are included in the sum.
8. Write a program that reads a date as an integer in the format MMDDYYYY. The program will call a function that prints print out the date in the format <Month Name> <day> , <year>.
9. Write a program that prints a table on two columns — table that helps converting miles into kilometer’s.
10. Write a program that prints a table on two columns that helps converting pounds to kilograms.
11. Write a program that reads two times in military format (0900, 1730) and prints the number of hours and minutes between the two times.
- Write a program to print one of the words negative, Zero, or positive, according to whether variable x is less than zero, zero, or greater than zero respectively?
#Question 1:
a=int(input("Enter the number"))
if a>0:
print("Positive number")
elif a<0:
print("Negative Number")
else:
print("Zero")
#output
Enter the number56
Positive number
2. Write a program that returns True if the input number is an even number, False otherwise.
#Question 2
a=int(input("Enter the number"))
if a%2==0:
print("True")
else:
print("False")
#Output
Enter the number24
True
3. Write a python program that calculates and prints the number of seconds in a year.
#Question 3
days_in_year = 365
hours_in_day = 24
minutes_in_hour = 60
seconds_in_minute = 60
result = days_in_year * hours_in_day * minutes_in_hour * seconds_in_minute
print("Number of seconds in a year are:",result)
#output:
Number of seconds in a year are: 31536000
4. Write a python program that accepts two integers from the user and prints a message saying if first number is divisible by second number or if it is not.
#Question 4
a=int(input("ENter first value"))
b=int(input("ENter second value"))
if a%b==0:
print("fully divisible")
else:
print("Not divisible")
#Output:
ENter first value10
ENter second value2
fully divisible
5. Write a program that asks the user number in a year in the range 2 to 365 and asks the first day of the year — Sunday or Monday or Tuesday etc., Then the program should display the day on the day -number that has been input.
a=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
b=int(input("""
Enter starting day of year
1. Sunday
2. Monday
3. Tuesday
4. Wednesday
5. Thursday
6. Friday
7. Saturday
"""))
c=a[b-1::]+a[:b-1:]
d=c*54
e=int(input("ENter the no of day"))
print(d[e-1])
#output
Enter starting day of year
1. Sunday
2. Monday
3. Tuesday
4. Wednesday
5. Thursday
6. Friday
7. Saturday
1
ENter the no of day21
Saturday
6. One foot equals to 12 inches. Write a function that accepts a length written in feet as an argument and returns this length written in inches. Write a second function that asks the user for a number of feet and returns this value. Write a third function that accepts a number of inches and displays this to the screen. Use these three functions to write a program that asks the user for a number of feet and tells them the corresponding number of inches.
a=int(input("ENter foot value"))
print("Inches :",a*12)
#Output
ENter foot value10
Inches : 120
With using Function
def feetToInches(lenFeet):
lenInch = lenFeet * 12
return lenInch
def getInput():
len = int(input("Enter length in feet: "))
return len
def displayLength(l):
print("Length in inches =", l)
ipLen = getInput()
inchLen = feetToInches(ipLen)
displayLength(inchLen)
#Output
Enter length in feet:10
Length in inches = 120
7. Write a program that reads an integer N from the keyboard computers and displays the sum of the numbers from N to (2*N) if N non negative. If N in a negative number, then its the sum of numbers from (2*N) to N. The starting and ending points are included in the sum.
n = int(input("Enter N: "))
sum = 0
if n < 0:
for i in range(2 * n, n + 1):
sum += i
else:
for i in range(n, 2 * n + 1):
sum += i
print("Sum =", sum)
#Output
Enter N: 2
Sum = 9
8. Write a program that reads a date as an integer in the format MMDDYYYY. The program will call a function that prints print out the date in the format <Month Name> <day> , <year>.