0% found this document useful (0 votes)
4 views3 pages

Final 2024 Python

The document contains three programming tasks: the first prompts for a score between 0.0 and 1.0 to assign a grade, the second calculates gross pay based on hours worked and hourly rate, and the third collects integer numbers until 'done' is entered, then outputs the largest and smallest numbers. Each task includes error handling for invalid inputs. The solutions are provided in Python code format.

Uploaded by

bashamasr5774
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Final 2024 Python

The document contains three programming tasks: the first prompts for a score between 0.0 and 1.0 to assign a grade, the second calculates gross pay based on hours worked and hourly rate, and the third collects integer numbers until 'done' is entered, then outputs the largest and smallest numbers. Each task includes error handling for invalid inputs. The solutions are provided in Python code format.

Uploaded by

bashamasr5774
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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:
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 message and exit.
Ans:
x=float(input('please enter your score '))
if 0.0<x<1.0:
if x>=0.9:
print("A")
elif x>=0.8:
print("B")
elif x>=0.7:
print("C")
elif x>=0.6:
print("D")
elif x<0.6:
print("F")
else:
print("the value is out of range")
-Write a program to prompt the user for hours and rate per hour using
input to compute gross pay. Pay should be the normal rate for hours up
to 40 and time-and-a-half for the hourly rate for convert all hours
worked above 40 hours. You should use input to read a string and float()
to the string to a number.

Ans:
num_hours=int(input("enter the number of hours "))
rate=float(input("enter the rate per hour "))
normal_hours=40
if num_hours<=normal_hours:
print(f"your salar is {num_hours*rate:.3f}")
else:
normal_pay=normal_hours*rate
over_time=num_hours-normal_hours
salary=normal_pay+over_time*1.5*rate
print(f"your salary is: {salary:.3f}")
-Write a program that repeatedly prompts a user for integer numbers
until the user enters 'done'. Once 'done' is entered, print out the largest
and smallest of the numbers. If the user enters anything other than a
valid number catch it with a try/except and put out an appropriate
message and ignore the number.
Ans:
lis=[]
z=0
while z==0:
x=(input('enter integers '))
if x == "done":
break
try:
y=int(x)
lis.append(y)
except:
print('not valid')

print(max(lis))
print(min(lis))

You might also like