You are on page 1of 3

1/3

204101 - Introduction to Computer


Lab Quiz#1 – Sequential Programming & Selection Programming

Student ID: __________________ Student Name ______________________________ Seq. _____


_________________________________________________________________________________
Instruction
I. Create a folder on drive D and name it using your student ID as follow: D:\StudentID
II. Write three Python programs to solve three problems specified below.
- For each problem, save your code file to the folder D:\StudentID with following name:
quiz1_ProblemNo_StudentID.py, for an example:
quiz1_1_620512345.py is for (Lab Quiz#1, Problem 1, Student ID 620512345)

Problem 1 (quiz1_1_StudentID.py): 10 Points


Write a Python program to calculate area of the circle using the formula below, where r is a radius and radius
must be greater than zero.

Circle Area = r2


r Let’s  = 3.141

Solution:
r = float(input("Input radius (r): "))
if r < 0:
print("Radius must be greater than Zero!!!")
else:
circle_area = 3.141*(r**2)
print("Area of the circle with radius %.2f = %.2f" %(r,
circle_area))

The program should function like these two examples:


Example I Example II
Input radius (r): 5.6 Input radius (r): -3
Area of the circle with radius 5.60 = 98.50 Radius must be greater than Zero!!!

_________________________________________________________________________________
(Set A)
2/3

Problem 2 (quiz1_2_StudentID.py): 10 Points


Write a Python program to calculate the shading area (the black color area),
where x is width and height of a square rectangle, and x
x must be greater than zero.
Note: If  is required, let’s  = 3.141. x
Solution:
x = float(input("Input width/height (x): "))
if x < 0:
print("Width/Height must be greater than Zero!!!")
else:
shade_area = (x**2) - (3.141*((x/2)**2))
print("Shading area with width/height %.2f = %.2f" %(x,
shade_area))

The program should function like these two examples:


Example I Example II
Input width/height (x): 6 Input width/height (x): -4.5
Shading area with width/height 6.00 = 7.73 Width/Height must be greater than Zero!!!

_________________________________________________________________________________
(Set A)
3/3

Problem 3 (quiz1_3_StudentID.py): 10 Points


Write a Python program to calculate wage per day for a worker. The way to calculate wage is displayed in the
table below:

Time Wage Rate


8.00 – 12.00 50 Baht/Hour
12.00 – 13.00 - (Lunch Break)
13.00 – 16.00 75 Baht/Hour

Inputs of this program are as follows:


- Start Hour must be greater than or equal to 8
- Finish Hour must be less than or equal to 16
- Start Hour must be less than Finish Hour
The program should function like these ten examples:
Input start hour: 7 Input start hour: 9
Input finish hour: 15 Input finish hour: 18
Invalid Start Hour Invalid Finish Hour
Input start hour: 15 Input start hour: 8
Input finish hour: 8 Input finish hour: 12
Start Hour must be less than Finish Hour Your wage for (8.00 - 12.00) is 200.00
Input start hour: 10 Input start hour: 12
Input finish hour: 14 Input finish hour: 13
Your wage for (10.00 - 14.00) is 175.00 Your wage for (12.00 - 13.00) is 0.00
Input start hour: 12 Input start hour: 13
Input finish hour: 15 Input finish hour: 16
Your wage for (12.00 - 15.00) is 150.00 Your wage for (13.00 - 16.00) is 225.00
Input start hour: 8 Input start hour: 8
Input finish hour: 13 Input finish hour: 16
Your wage for (8.00 - 13.00) is 200.00 Your wage for (8.00 - 16.00) is 425.00

Find solution yourself

_________________________________________________________________________________
(Set A)

You might also like