-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsurvey.py
More file actions
29 lines (22 loc) · 800 Bytes
/
survey.py
File metadata and controls
29 lines (22 loc) · 800 Bytes
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
import sys
#Returns only valid answer
def get_answer():
valid_input=False
while not valid_input:
try:
answer =int(raw_input());
if not (1 <= answer <= 5):
raise ValueError()
valid_input=True
return answer
except ValueError:
print "Please only enter values between 1-5"
def main():
print("Hello, answer 5 to 1 according to your satisfaction")
with open("res/user_answers.txt","a") as user_answers, open("res/questions.txt", "r") as questions_file:
for line in questions_file:
print (line)
user_answers.write(bytes(get_answer()))
user_answers.write("\n")
print("Thanks for answering the survey!")
main()