用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

surtr    -  云代码空间

——

加减法运算(能报错)

2022-03-20|240阅||

摘要:import random input('按任意键开始游戏') while 1==1:     d=input('请问你想要连续答对几道通关:')     while not d.isdigit():         d=input('请重输:')     c = int(d)

import random
input('按任意键开始游戏')
while 1==1:
    d=input('请问你想要连续答对几道通关:')
    while not d.isdigit():
        d=input('请重输:')
    c = int(d)


    hh=True
    while hh:
        g=input('请输入你想要的数字范围:(请用\',\'间隔开,且必须为半角输入)')
        while int(g.count(','))!=1:
            g=input('请输入你想要的数字范围:(请用\',\'间隔开,且必须为半角输入)')
        while g.index(',') ==0 or g.index(',') ==len(g)-1:
            g=input('请输入你想要的数字范围:(请用\',\'间隔开,且必须为半角输入)')
        h=g.index(',')
        if not g[:h].isdigit():
            continue
        if not g[h+1:].isdigit():
            continue
        k=int(g[:h])
        l=int(g[h+1:])
        if k<l:
            hh=False
        else:
            input('左边的数字应小于右边的数字')
    i=0
    while i < c:  
        e=random.randint(1,2)
        a=random.randint(k,l)
        b=random.randint(k,l)
        if e == 1:
            answer=input('%d+%d='%(a,b))
            while not answer.isdigit():
                if answer!='':
                
                    if answer[0] in '-':
                        answe=answer[1:]
                        if not answe.isdigit():
                            answer=input('请重输:')
                            continue
                        else:
                            break
                answer=input('请重输:')
            if int(answer) ==a+b:
                print('答对了,进入下一题。')
                i+=1
            else:
                print('错误,重新开始')
                f=open("错题本.txt",'a+')
                f.write('%d+%d='%(a,b)+'\n')
                f.close() 
                i=0
    
        if e == 2:
            answer=input('%d-%d='%(a,b))
            while not answer.isdigit():
                if answer!='':
                
                    if answer[0] in '-':
                        answe=answer[1:]
                        if not answe.isdigit():
                            answer=input('请重输:')
                            continue
                        else:
                            break
                answer=input('请重输:')
            if int(answer) ==a-b:
                print('答对了,进入下一题。')
                i+=1
            else:
                print('错误,重新开始')
                f=open("错题本.txt",'a+')
                f.write('%d+%d='%(a,b)+'\n')
                f.close() 
                i=0


    print('恭喜你通关。')
    while 1==1:
        sd=input('还要再来吗?(1.是  2.否):')
        if sd=='1':
            print('\n'*40)
            break
        if sd=='2':
            exit()
    

顶 2踩 0收藏
文章评论
    发表评论

    个人资料

    • 昵称: surtr
    • 等级: 初级程序员
    • 积分: 12
    • 代码: 0 个
    • 文章: 2 篇
    • 随想: 0 条
    • 访问: 1 次
    • 关注

    人气代码

      标签

      最新提问

        站长推荐