Programming Concept if Then Else Answers
Programming Concept if Then Else Answers
num = int(input())
if num % 2 == 0:
print("Even")
else:
print("Odd")
2. Input a number and print if it is even or odd. Input the percentage of a student in Examination and
print if the student has passed or failed.
percentage = float(input())
print("Pass")
else:
print("Fail")
3. A passenger is allowed to carry 30kg of luggage with him. If there is extra luggage, then he has to
pay fine at the rate Rs.200 per kg. Write a program to input the weight of luggage and print the Fine if
there is any or Zero otherwise.
weight = float(input())
extra = weight - 30
if extra > 0:
else:
print("fine is",0)
4. An employee is paid salary depending on the number of hours worked and his hourly rate. If he
works more than 40 hours in a week than he is paid over time and rate for overtime is double the
normal rate. Write a program to input the hourly rate and hours worked of an employee. Print this
Normal Salary, Overtime Salary and Gross Salary.
hourly_rate = int(input())
print("Hours worked:")
hours = int(input())
normal = 40 * hourly_rate
extra = hours – 40
print("Normal:",normal)
print("Overtime:",overtime)
IF …. ELSEIF structure
5. Input the percentage of a student in an examination and print his grade.
>= 90 A
>= 80 B
>=70 C
>=60 D
>=50 E
percentage = float(input())
grade = "A"
else:
else:
grade = "C"
else:
grade = "D"
else:
grade = "E"
else:
grade = "U"
print(grade)
Business Allowed weight 50kg Rs. 200/kg Fine for extra weight
Economy Allowed weight 30kg Rs. 400/kg Fine for extra weight
if ticket_type == "Economy":
weightallowed = 30
rate = 400
extra = weight - weightallowed
if extra > 0:
fine = extra * rate
print("Please pay fine:",fine)
else:
print("fine is: ", 0)
8. A student takes two tests in a semester. Max Marks are 100. His grade is “Distinction” if he scores
80 or above in both the subjects “Pass” if Aggregate is 100 or above “Fail” otherwise
10. Input the marks obtained by a student in test. Print if the Marks are Valid or invalid. Marks from 0
to 100 (inclusive) means valid.
11. There are two types of ticket issued by an airline. Business and Economy. Both are allowed to carry a
limited luggage weight them. Write a program to input the ticket type and weight of luggage of the
passenger. Calculate his fine according to the grid given below or Zero otherwise.
Business Allowed weight 50kg Rs. 200/kg Fine for extra weight
Economy Allowed weight 30kg Rs. 400/kg Fine for extra weight