Jun-04-2020, 01:02 PM
I want to check all the input i receive, i know i can put float or int at the beginning of the input but i want it to print an error message when error occurs.(a way to do this?)
I used try and except twice.(works but can't use it for each input i receive if there are too many).But the first inputs i didn't use it,is there a way to use it once or another way to check them once and for all. Also all the inputs should be between 0 and 100 how do i write that in a simpler way or just once and not separately for each.
I used try and except twice.(works but can't use it for each input i receive if there are too many).But the first inputs i didn't use it,is there a way to use it once or another way to check them once and for all. Also all the inputs should be between 0 and 100 how do i write that in a simpler way or just once and not separately for each.
midterm_1=input('Please enter your first midterm score: ')
midterm_2=input('Please enter your second midterm score: ' )
midterm_total= float(midterm_1)*(20/100) + float(midterm_2) * (20/100)
print('your total percentage from midterm scores is: ' + str(midterm_total))
summary_paper=input('Please enter your summary paper score: ')
summary_total= float(summary_paper) * (10/100)
print('your total percentage from summary paper is: ' + str(summary_total))
response_paper=input('Please enter your response paper score: ')
response_total= float(response_paper) * (20/100)
print('your total percentage from response paper is: ' + str(response_total))
i=1
my_list = []
while i <=10:
try:
my_list.append(int(input('please enter your discussions scores: ')))
i += 1
except:
print('you made an error,please try again')
print(my_list)
l=[]
for x in my_list:
dis_score = x * (2/100)
l.append(dis_score)
print('your total percentage from discussion scores is: '+ str(sum(l)))
k=1
my_list2 = []
while k <= 5:
try:
my_list2.append(int(input('please enter your top hat scores: ')))
k += 1
except:
print('you made an error,please try again')
print(my_list2)
s=[]
for x in my_list2:
tophat_score = x * (2/100)
s.append(tophat_score)
print('your total percentage from discussion scores is: '+ str(sum(s)))
total_sum = midterm_total + summary_total + response_total + sum(l)+ sum(s)
if total_sum >= 86:
print('You received an A with total score of ' +str(total_sum))
elif total_sum>=74 and total_sum<=85 :
print('You received a B with total score of ' +str(total_sum))
elif total_sum >=62 and total_sum<=73:
print('You received an C with total score of ' +str(total_sum))
elif total_sum >=54 and total_sum <=61:
print('You received an D with total score of ' +str(total_sum))
else:
print('you failed the course')
