-
Notifications
You must be signed in to change notification settings - Fork 0
/
quiz.py
107 lines (89 loc) · 2.28 KB
/
quiz.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/python
# Quiz Mode
import time
import sys
import random
#----------------------------------
# Mode Selector
greeting = "Welcome to Quiz Mode."
menu = "Would you like to Read the time (1), or Set the time (2)?"
prompt = "User Selection:"
#u_input = input("User Selection: ")
m_read = 1
s_read = 2
def modeSelect():
print greeting
print menu
u_input = int(raw_input("User Selection: ")) #Cast required
# print u_input
if u_input == 1:
read()
elif u_input == 2:
Set()
#----------------------------------
# Read Mode
def read():
h = random.randrange(1,12)
m = random.randrange(0,59)
attempt = 0
correct = 0
print "*************************"
print 'Welcome to Read Mode.'
print "*************************"
r_prompt = 'What time is it?'
# Move stepper motors here
print r_prompt
print h, m # For debugging purposes only
u_hr = int(raw_input("Hour: "))
u_min = int(raw_input("Minute :"))
# Correct Answer ************** #
if u_hr == h and u_min == m:
print 'Correct! Good Job!'
correct += 1
control = int(raw_input('Try again? 1 Yes 2 No '))
if control == 1:
read()
elif control == 2:
print 'Thanks for playing. Goodbye!'
quit() # Return to normal mode
# Record activity to database
# Wrong Answer **************** #
else:
print "*************************"
print 'Sorry! That is not the correct time. Try again.'
while attempt != 3:
# print 'Wrong answer. Try it again'
u_hr = int(raw_input("Hour: "))
u_min = int(raw_input("Minute :"))
if u_hr == h and u_min == m:
print 'Correct! Good Job!'
correct += 1
control = int(raw_input('Try again? 1 Yes 2 No '))
if control == 1:
read()
elif control == 2:
print 'Thanks for playing. Goodbye!'
quit() # Return to normal mode
else:
attempt += 1
print 'Correct answer is...'
print h, m
print '*************************'
read()
# Record activity to database
def Set():
h = random.randrange(0,12)
m = random.randrange(0,59)
print "*************************"
print 'Welcome to Set Mode.'
print "*************************"
r_prompt = 'Set the clock to the following time:'
# Display value on LCD screen
print h , m
print r_prompt
u_hr = int(raw_input("Hour: "))
u_min = int(raw_input("Minute :"))
print 'Done'
def main():
modeSelect()
main()