So i have written up a 10 question multichoice quiz. As an extra i thought i may try add a function that times how long the user takes to complete the quiz and displays the total time at the end. I think its this at the start: start = time.clock() then at the end:duration = time.clock() - start.
Here is the start and finish of my code:
print "Hi there, welcome to Mason's who wants to be a millionaire New Zealand Edition"
time.sleep(3)
def main():
name=raw_input( "Please type in your name then hit Enter")
print '\nHello there', name, 'I hope you have fun. Enjoy and good luck!!'
print '\nReady'
time.sleep(1)
print '\n3'
time.sleep(1)
print '\n2'
time.sleep(1)
print '\n1'
time.sleep(1)
print'\nGo!'
Question1()
time.sleep(2)
Question2()
time.sleep(2)
Question3()
time.sleep(2)
Question4()
time.sleep(2)
Question5()
time.sleep(2)
Question6()
time.sleep(2)
Question7()
time.sleep(2)
Question8()
time.sleep(2)
Question9()
time.sleep(2)
Question10()
start = time.clock()
def Question1():
print '\nWhat is the capital of New Zealand?'
print '\nA) Invercargill'
print '\nB) Wellington'
print '\nC) Dunedin'
print '\nD) Auckland'
ans1=raw_input ('Answer: ')
if ans1 == 'A' or ans1=='a':
print 'Wrong!'
elif ans1 == 'B'or ans1=='b':
print 'Correct! Wellington is the Capital of New Zealand, Nice work!'
elif ans1 == 'C'or ans1== 'c':
print 'Wrong!'
elif ans1 == 'D'or ans1== 'd':
print 'Wrong!'
and the end looks like this
def Question10():
print'\nName the body of water that separates the North and South Islands'
print '\nA)Bass Strait'
print '\nB)Tasman Sea'
print '\nC)Foveaux Strait'
print '\nD)Cook Strait'
ans10=raw_input ('Answer: ')
if ans10 == 'A' or ans10=='a':
print 'Wrong!'
elif ans10 == 'B'or ans10=='b':
print 'Wrong!'
elif ans10 == 'C'or ans10== 'c':
print 'Wrong!'
elif ans10 == 'D'or ans10== 'd':
print 'Correct! The body of water that separates the North and South Islands is the Cook Strait!'
duration = time.clock() - start
main()
But i dont get how to display it
Thanks in advance

New Topic/Question
Reply



MultiQuote






|