import random
def GenEx(count):
signs = ['+', '-', '*', '/']
for _ in range(count):
fn = random.randint(-20, 20)
sn = random.randint(-20, 20)
ex = '{0} {1} {2}'.format(fn, random.choice(signs), sn)
yield (ex + ' = ?', eval(ex))
IsGameRun = True
while IsGameRun:
TrueAnsws = 0
for ex, check in GenEx(2):
print(ex)
resvAnsw = float(input())
if resvAnsw == check: TrueAnsws += 1;
IsRetry = input('You correctly solved '+str(TrueAnsws)+' examples. Do you want to try again? Y/N \n')
if IsRetry == 'Y': IsGameRun = True
else: IsGameRun = False
Объяснение:
import random
def GenEx(count):
signs = ['+', '-', '*', '/']
for _ in range(count):
fn = random.randint(-20, 20)
sn = random.randint(-20, 20)
ex = '{0} {1} {2}'.format(fn, random.choice(signs), sn)
yield (ex + ' = ?', eval(ex))
IsGameRun = True
while IsGameRun:
TrueAnsws = 0
for ex, check in GenEx(2):
print(ex)
resvAnsw = float(input())
if resvAnsw == check: TrueAnsws += 1;
IsRetry = input('You correctly solved '+str(TrueAnsws)+' examples. Do you want to try again? Y/N \n')
if IsRetry == 'Y': IsGameRun = True
else: IsGameRun = False
Объяснение: