猫史档案馆


【Python作品分享】两位数的连加连减【教程贴】

用户:祁思杰祁思杰查看:0 回复:0 评论:0 创建时间:2019-09-07T17:48:11


【作品展示】

center_image

 

【作品介绍】

三个随机的两位数连加或连减,每次20道题,做完会有成绩显示,满分100分哦

 

【作品源代码】

import random


#开始进入Python的世界

score = 0



for i in range(1,21):
    a = random.randint(10, 99)
    b = random.randint(10, 99)
    c = random.randint(10, 99)
    x = random.choice([True, False])
    y = random.choice([True, False])
    print("第%d 题:"%i)

    if x == False:
        if a < b:
            a, b = b, a
        s1 = a - b
        if y == False:
            if s1 < c:
                print("1: %d " %c+"- "+"(%d " %a+"- ""%d) " %b+"=")
                s2 = c - s1
            else:
                print("2: %d "%a+"- "+"%d "%b+"- ""%d "%c+"=")
                s2 = s1 - c
            ans = int(input('答案是多少?'))
            if ans != s2:
                print("答错了!")
                
            else:
                print("Good!")
                score += 5
        else:
            s2 = s1 + c
            print("3: %d " % a+"- "+"%d " % b+"+ ""%d " % c+"=")
            ans = int(input('答案是多少?'))
            if ans != s2:
                print("答错了!")
            else:
                print("Good!")
                score += 5
    else:
        s1 = a + b
        if y == False:
            if s1 < c:
                print("4: %d " % c+"+ "+"(%d " % a + "- ""%d) " % b+ "=")
                s2 = c - s1
            else:
                print("5: %d " %a+ "+ " + "%d " % b + "- ""%d " % c+ "=")
                s2 = s1 - c
            ans = int(input('答案是多少?'))
            if ans != s2:
                print("答错了!")
            else:
                print("Good!")
                score += 5
        else:
            s2 = s1 + c
            print("6: %d " % a+"+ "+"%d " % b+"+ ""%d " % c+"=")
            ans = int(input('答案是多少?'))
            if ans != s2:
                print("答错了!")
            else:
                print("Good!")
                score += 5

print("你的成绩是: %d"%score)


    


 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 0下一页