Lab03 (33817545)
Lab03 (33817545)
Exercise 1:
Develop a Python program that:
• Reads the age of a person.
• Identifies whether that person is eligible for voting in an election or not.
Exercise 2:
Write down a Python program to:
• Read a positive integer number n.
• Print out a proper message according to the fact that it is an odd or an even value.
Exercise 3:
Write a program to prompt the user for hours and hourly rate to compute gross pay. At this time,
if entered hours are more than 40 hours, a program should calculate gross pay for exceeding hours
with a 1.5 times higher pay rate per hour.
Sample Output:
Enter Hours: 35
Enter Rate: 2.75
Pay: 96.25
Exercise 4:
Rewrite your pay program using try and except so that your program handles non-numeric input
gracefully by printing a message and exiting the program. The following shows two executions of
the program:
Sample Output:
Enter Hours: 38
Enter Rate: eight
Error, please enter a number using digits.
Enter Hours: thirty eight
Error, please enter a number using digits.
Exercise 5:
Write down a Python program which reads three real numbers from the keyboard and displays the
maximum among them, also saying if it corresponds to the first, second or third value introduced
by the user.
Sample Output:
Introduce the first value: 3.5
Introduce the second value: 12.1
Introduce the third value: -1.0
The second value (12.1) is the largest one.
Exercise 6:
Develop a Python program that:
• Reads the units of electricity consumed by a user;
• Calculates the electricity bill based on consumed unit of electricity.
• Electricity bill should be calculated according to the following criteria:
Unit Price
First 100 units No charge
After 100 units (until 200) 500 UZS
After 200 units 600 UZS
Sample Output:
Enter the units of electricity: 220
Electricity Bill: 62000 UZS
Exercise 7:
Write a program to prompt for a score between 0 and 100. If the score is out of range, print an
error message. If the score is between 0 and 100, print a grade according to the following criteria:
Score Grade
From 90 to 100 A
From 80 to 90 B
From 70 to 80 C
From 60 to 70 D
Less than 60 F
Sample Output:
Enter score: 97
Grade: A
Enter score: 81
Grade: B
Exercise 8:
Write a program to check whether the last digit of a number (entered by a user) is divisible by 3 or
not.
Hint: ‘number % 10’ operation can be used to find the last digit of a number.
Exercise 9:
Develop a Python program that reads a letter (entered by a user) and prints out the proper message
according to the fact of whether an entered letter is a vowel or consonant.
Exercise 10:
Sample Output:
Enter your input: 77
Your input is integer
Enter your input: hello
Your input is NOT integer
Exercise 11:
The government decided to provide university students with scholarships. However, to be eligible
to apply for a scholarship, a student has to be between 16 and 24 and should have a higher than
80% GPA in his/her academics.
Develop a program that:
• reads the name, age, and GPA score of a student.
• displays whether the student is eligible to apply for a scholarship.
Exercise 12:
Write a program which can check if the character entered by a user is uppercase or lowercase.
Hint: Consider the ASCII table; use ord()function to get a character value (according to ASCII
table)
Exercise 13:
Write down a Python program which:
• Reads three real numbers (a, b and c)
• Checks whether a, b and c may (or may not) represent the sides’ lengths of a triangle. If
yes, the program must also determine the triangle type, distinguishing among the
following cases:
➢ Equilateral triangle, a==b==c
➢ Isosceles triangle, a==b!=c or b==c!=a or a==c!=b
➢ Scalene triangle a!=b!=c
➢ Rectangular triangle c*c==a*a+b*b or a*a==b*b+c*c or b*b==a*a+c*c
Recall that, in any triangle, the length of each side must be smaller than the sum of the lengths of
the other two sides. a<b+c, b<a+c, c<a+b.
Exercise 14:
Write down a Python program which:
• Reads year from the keyboard.
• Displays an appropriate message on the screen according to whether the year is a leap year
or not.
Leap year Definition: All years perfectly divisible by 4 are leap years except for century years
(years ending with 00), which is a leap year only it is perfectly divisible by 400. For example:
2012, 2004, 1968 etc. are leap year but, 1971, 2006 etc. are not leap year. Similarly, 1200,