1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 随机生成20以内加减法 5次答题并统计正确和错误题数

随机生成20以内加减法 5次答题并统计正确和错误题数

时间:2021-07-20 09:40:11

相关推荐

随机生成20以内加减法 5次答题并统计正确和错误题数

import random

right = 0

wrong = 0

print('答题系统,5道题,现在开始!')

count = 1

while count < 6:

a = random.randint(1,20)

b = random.randint(1,20)

s = '+-'

fh = random.choice(s)

if a < b and fh =='-':

result = int(input('%d %s %d =' % (b, fh, a)))

if result == b-a:

print('答对了')

right += 1

else:

print('答错了,答案是:',(b-a))

wrong += 1

elif a > b and fh == '-':

result = int(input('%d %s %d =' % (a, fh, b)))

if result == a-b:

print('答对了')

right += 1

else:

print('答错了,答案是:',(a-b))

wrong += 1

else:

result = int(input('%d %s %d =' % (a, fh, b)))

if result == a+b:

print('答对了')

right += 1

else:

print('答错了,答案是:', (a - b))

wrong += 1

count += 1

print('答题结束,正确%d道,错误%d道' % (right,wrong))

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。