-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy2226_potega_pierwiastek.py
More file actions
59 lines (47 loc) · 1.12 KB
/
py2226_potega_pierwiastek.py
File metadata and controls
59 lines (47 loc) · 1.12 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
# coded by h4sski
import random
from re import A
MIN = 2
MAX = 10
def get_rand(up):
return random.randrange(MIN, up)
def potega(w):
a = get_rand(MAX)
mistake = 0
while True:
v = int(input(f'{a}^{w} = '))
v_correct = a ** w
if v == v_correct:
break
else:
mistake += 1
print(' Zle, jeszcze raz:')
return mistake
def pierwiastek(w):
if w == 3:
a = get_rand(4)
else:
a = get_rand(MAX)
mistakes = 0
while True:
v_correct = a ** w
# print(f'{a}^{w} = {v_correct}')
v = int(input(f'Pierwiastek {w} stopnia z {v_correct} = '))
if v == a:
break
else:
mistakes += 1
print('Zle, jeszcze raz:')
return mistakes
def main():
mistakes = 0
wykladnik = random.choice([2, 3])
for _ in range(10):
r = random.choice(['p', 'p']) # q for sqrt()
if r == 'p':
mistakes += potega(wykladnik)
else:
mistakes += pierwiastek(wykladnik)
print()
print(f'Popoelniles {mistakes} bledow.')
main()