Python Unit2 Programs
Python Unit2 Programs
Python Unit2 Programs
if num % 2 == 0:
print(f"{num} is even.")
else:
print(f"{num} is odd.")
x=10
if x>0 :
x=x+1
print(x)
else:
if number % 2 != 0:
print(f"{number} is odd.")
else:
#Question5 : Write a program to print “Excellent” if marks is greater than 95 otherwise print
“Good”
print("Excellent")
else:
print("Good")
#Question6: Write a program to know profit or loss in a particular sell and purchase.
print(f"Profit: {profit}")
print(f"Loss: {loss}")
else:
#Question7 : Write a program to check if user has got honours in the examination or not
else:
o Good : Marks obtained greater than 80% and less than equal to 95%.
o Average : Marks obtained greater than 60% and less than equal to 80%.
print("Grade: Excellent")
print("Grade: Good")
print("Grade: Average")
else:
'''Question 9Write a program to generate electricity bill on basis of following criteria. First 100
units
as 3 rupees per unit, next 100 units as 4 rupees per unit and then rest would be
calculated as 5 rupees per unit. Total units consumed would be entered by user and
bill_amount = 0
# Calculate the bill based on the units consumed
bill_amount = units_consumed * 3
else:
''' Question 10 :Write a program to calculate salary on the basis of following criteria if
basic<20000,
# Initialize DA
else:
total_salary = basic_salary + da
# Print the total salary
''' Question 11.Write a program to take an integer number from 1 to 7 from user and print
corresponding weekday, consider 1 as Monday, also print if there is incorrect choice.'''
if day_number == 1:
print("Monday")
elif day_number == 2:
print("Tuesday")
elif day_number == 3:
print("Wednesday")
elif day_number == 4:
print("Thursday")
elif day_number == 5:
print("Friday")
elif day_number == 6:
print("Saturday")
elif day_number == 7:
print("Sunday")
else:
is less than 18, otherwise print “You are above 18”. You should also check that age could not be
less than 0. If so then print a message “Age could not be less than 0”.'''
if age>0:
if age<18:
else:
else:
maximum = num1
maximum = num2
else:
maximum = num3
#Print the maximum number
''' 'Question
: Write a program to enter integer from 1 to 12 and print corresponding number of days in
the month'''
if month_number == 1: # January
days = 31
days = 31
days = 30
days = 31
days = 30
days = 31
days = 31
days = 31
days = 30
days = 31
else:
exit()
#Question Write a program to print 4 natural numbers i.e. 1,2,3,4 using while loop.
# Initialize the counter
num = 1
print(num)
# Question :Write a program to print natural for first n numbers, where n would be entered by user.
n = int(input("Enter a positive integer (n) to print the first n natural numbers: "))
print(num)