Using Python - Implement function inValues() that asks the user to input a set o
ID: 3762935 • Letter: U
Question
Using Python - Implement function inValues() that asks the user to input a set of nonzero floating- point values. When the user enters a value that is not a number, give the user a second chance to enter the value. After two mistakes in a row, quit the program. Add all correctly specified values when the user enters 0. Use exception handling to detect improper inputs.
specified values when the user enters 0. Use exception handling to detect improper inputs.
>>> inValues()
Please enter a number: 4.75
Please enter a number: 2,25
Error. Please re-enter the value.
Please enter a number: 2.25
Please enter a number: 0
7.0
>>> inValues()
Please enter a number: 3.4
Please enter a number: 3,4
Error. Please re-enter the value.
Please enter a number: 3,4
Two errors in a row. Quitting ...
Explanation / Answer
def inValues():
counter = 0
a=0
while True:
if counter <= 2:
try:
value=input(‘enter a value’)
counter=1
float value = float(value)
break
else:
break
except:
if value!=nonzero
print(‘reenter a value’)
errorcounter+=1
printf(‘two mistakes quit the program’)
except:
a += float(value)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.