python自制小卷子(数学测试)

最近几天突发灵感,做了这么一张数学小卷子

import random
from random import randint#导入随机数
score=0#用来计分
note=0#用来记答过的题数
a=random.randint(1,100)#设置变量
b=random.randint(1,100)
print(a,'+',b,'=','?')#出题
c=int(input(''))
if c==a+b:
    score+=1
    note+=1
    d=int(input('回答正确n1.下一题  2.结束考试t3查看分数n'))
    if d == 2:
        print('考试结束n你一共答对了:', score, '道题', '你一共答了', note, '道题')
    if d == 3:
        print('你一共答对了:', score, '道题', '你一共答了', note, '道题n')
        d = int(input('1. 继续考试 2. 结束考试n'))
    while d==1:
        a = random.randint(1, 100)
        b = random.randint(1, 100)
        print(a,'+',b,'=','?')
        c = int(input(''))
        if c==a+b:
            score += 1
            note += 1
            d = int(input('回答正确n1.下一题  2.结束考试t3查看分数n'))
        else:
           note+=1
           d = int(input('回答错误n1.下一题  2.结束考试t3查看分数n'))
        if d == 2:
            print('考试结束n你一共答对了:', score, '道题', '你一共答了', note, '道题')
        if d == 3:
            print('你一共答对了:', score, '道题', '你一共答了', note, '道题',end='n')
            d = int(input('1. 继续考试 2. 结束考试n'))
else:
    print('回答错误')
    note+=1
    d = int(input('1.下一题  2.结束考试t3查看分数n'))
    if d == 2:
        print('考试结束n你一共答对了:', score, '道题', '你一共答了', note, '道题')
    if d == 3:
        print('你一共答对了:', score, '道题', '你一共答了', note, '道题n')
        d = int(input('1. 继续考试 2. 结束考试n'))

    while d == 1:
        a = random.randint(1, 100)
        b = random.randint(1, 100)
        print(a, '+', b, '=', '?')
        c = int(input(''))
        if c == a + b:
            score += 1
            note += 1
            d = int(input('回答正确n1.下一题  2.结束考试t3查看分数n'))
        else:
           note+=1
           d = int(input('回答错误n1.下一题  2.结束考试t3查看分数n'))
        if d == 2:
            print('考试结束n你一共答对了:', score, '道题', '你一共答了', note, '道题')
        if d == 3:
            print('你一共答对了:', score, '道题', '你一共答了', note, '道题n')
            d = int(input('1. 继续考试 2. 结束考试n'))

本人学python不到一个月,代码部分肯定有很多可以改进的地方,希望大佬多多指点

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码

)">
< <上一篇

)">
下一篇>>