모두를 위한 파이썬_Chapter03

제이브로·2021년 10월 7일
0

모두를위한파이썬

목록 보기
4/13

Chapter 03

3.1 Write a program to prompt the user for hours and rate per hour using input to compute gross pay.
Pay the hourly rate for the hours up to 40 and 1.5 times the hourly rate for all hours worked above 40 hours.
Use 45 hours and a rate of 10.50 per hour to test the program (the pay should be 498.75).
You should use input to read a string and float() to convert the string to a number.
Do not worry about error checking the user input - assume the user types numbers properly.

hrs = input("Enter Hours:")
h = float(hrs)
rate = input("Enter rate:")
r = float(rate)

if h > 40 :
    sum = (40 * r) + (h - 40) * 1.5 * r
else:
    sum = h * r
    
print(sum)

3.3 Write a program to prompt for a score between 0.0 and 1.0.
If the score is out of range, print an error.
If the score is between 0.0 and 1.0, print a grade using the following table:
Score Grade

= 0.9 A
= 0.8 B
= 0.7 C
= 0.6 D
< 0.6 F
If the user enters a value out of range, print a suitable error message and exit. For the test, enter a score of 0.85.

score = input("Enter Score: ")
score = float(score)

try:
    0.0 <= score <= 1.0
except:
    print("out of range")

if score >= 0.9:
    print("A")
elif score >= 0.8:
    print("B")
elif score >= 0.7:
    print("C")
elif score >= 0.6:
    print("D")
elif score < 0.6:
    print("F")
profile
기록하지 않으면 기록되지 않는다.

0개의 댓글