-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcq.py
executable file
·53 lines (46 loc) · 1.52 KB
/
cq.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
#!/usr/bin/python3
"""
Simple math game - choose quickly
"""
from random import randint
from random import choice
def make_unknown(computer_number, result, operation):
if operation == "+":
return result - computer_number
if operation == "-":
return result + computer_number
# For future
if operation == "*":
return result // computer_number
if operation == "//":
return result * computer_number
def guess():
# Check user input and return correct answer
while True:
number = input("Press 'e(xit)' or any to return...")
if number == 'e':
exit()
else:
return
def main():
while True:
# Создать два случайных числа
computer_number = randint(0, 100)
result = randint(0, 100)
# Выбрать случайное действие
operation_list = ["+", "-"]
operation = choice(operation_list)
unknown = make_unknown(computer_number, result, operation)
# Создать выражение
print ("Find X:")
print ("x", operation, computer_number, " = ", result)
# Попросить пользователя найти решение
answer = input("Input answer: ")
# Проверить верен ли ответ
if int(answer) == int(unknown):
print("You win")
else:
print("You lose. Right answer is ...", unknown )
guess()
if __name__ == "__main__":
main()