2. Python Program Exercises_DECISION MAKING
2. Python Program Exercises_DECISION MAKING
Lab Exercises -2
Decision Making/ Conditional Statements
1. Check whether the given number is a Positive or Negative number.
num = int(input("Enter a number: "))
if num > 0:
print("Positive number")
elif num == 0:
print("Zero")
else:
print("Negative number")
2. Check whether the given number is Odd or Even.
num = int(input("Enter a number: "))
if (num % 2) == 0:
print("{0} is Even".format(num))
else:
print("{0} is Odd".format(num))
# if not divided by both 400 (century year) and 4 (not century year)
# year is not leap year
else:
print("{0} is not a leap year".format(year))
5. Vehicle to be serviced or not
km_reading=int(input("Enter the kilometer value:"))
if km_reading>2500:
print("Vehicle service is recommended")
else:
print("Service after 2500km")
6. ATM withdrawal allowed or not
withdrawal_amnt=int(input("Enter the amount:"))
if withdrawal_amnt>2000:
print("Exceeding daily withdrawl limit")
else:
print("Transaction Successful")
7. Exam Result
marks=int(input("Enter the marks scored"))
if marks<0:
print("Enter valid marks")
elif marks>50:
print("Cleared the exam")
else:
print("Resit for the exam")
8. Chained conditional using elif
color = int(input("Enter the color value:"))
if color == 1:
print("Violet Color")
elif color == 2:
print("Indigo Color")
elif color == 3:
print("Blue Color")
elif color == 4:
print("Green Color")
elif color == 5:
print("Yellow Color")
elif color == 6:
print("Orange Color")
elif color == 7:
print("Red Color")
else:
print("Invalid Color Entry!")