In: Computer Science
Develop a python program to create a quiz with limited time and attempts!!! Add comments and screenshot of running the program
quiz could be of anything like , what's the sum of
2&2.
There should be number of attempts(limited) suppose if the answer
is wrong.
OUTPUT:
CODE:
TEXT:
import time
def question(maxattempts,maxtime):
attempts = 0
start = time.perf_counter()
answered = False
#continue till maxattempts
while attempts < maxattempts:
ans = input('Whats the sum of 2 and 2 : ')
if ans == '4':
answered = True
break
attempts = attempts + 1
stop = time.perf_counter()
#check if the time exceeded or the attempts exceeded
if stop - start >= maxtime or attempts >= maxattempts:
return False
else:
return True
if question(4,10):
print('you won')
else:
print('Chance lost')