-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperation.py
More file actions
81 lines (41 loc) · 1.4 KB
/
Operation.py
File metadata and controls
81 lines (41 loc) · 1.4 KB
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
import random
print("")
print("Welcome to operation guesser.")
scr = 0
for ctr in range(5):
print("")
print("Your score is: ", scr, " out of five.")
aval = random.randrange(1, 10)
bval = random.randrange(1, 10)
opr = random.randrange(5)
oprlst = [ "addition", "subtraction", "multiplication", "division", "to the power of"]
ares = int(aval + bval)
sres = int(aval - bval)
mres = int(aval * bval)
dres = int(aval / bval)
pres = int(aval ^ bval)
reslst = [ares, sres, mres, dres, pres]
statres = reslst[opr]
print("")
print(aval, " / ", bval, " / ", statres)
print("")
print("What operation makes the first two numbers result in the whole number value of the third?")
print("")
oprin = input("Press 0 for addition, 1 for subtraction, 2 for multiplication, 3 for division and 4 for to the power of: ")
print("")
opin = int(oprin)
if opin < 0 or opin > 4:
opin = 0
plastres = reslst[opin]
anslst = []
for elem in reslst:
if plastres == elem:
anslst.append(opin)
resstr = oprlst[opin]
if opin in anslst:
print("You guessed ", resstr, " which is correct.")
scr += 1
if opin not in anslst:
print("You guessed ", resstr, " which is not correct.")
print("")
print("Your total score is: ", scr, " out of 5 possible. Thank you for playing.")