m0_64385506(◦˙▽˙◦) 2022-03-22 20:17 采纳率: 92.9%
浏览 87
已结题

请问一下我的程序为什么不对(有问题描述)

自动出10道题并判分 if_auto_score.py
随机产生两个[1,10]内的整数和“+-*/”符号中的一个
输出表达式让用户输入其计算的答案
对结果进行判断,并输出判断的结果
关于随机数
import random
random.randint(1, 9)
random.random( ) 0-1之间的数,不含1
下面是程序

import random
a=int(random.randint(1, 10))
print(a)
b=int(random.randint(1, 10))
print(b)
c=int(random.randint(1,4) )
if c==1:
e=a+b
print(a,'+',b,'=','几')
elif c==2:
e=a-b
print(a,'-',b,'=','几')
elif c==3:
print(a,'',b,'=','几')
e=a
b
else:
print(a,'/',b,'=','几')
e=a/b
d=float(input())
if e==d:
print('dui le')
else:
print('bu dui')

  • 写回答

1条回答 默认 最新

  • Py小郑 Python领域潜力新星 2022-03-22 20:36
    关注

    img

    
    import random
    
    import random
    i=1
    while i<=10:
        a=int(random.randint(1, 10))
        b=int(random.randint(1, 10))
        c=int(random.randint(1,4) )
        if c==1:
            e=a+b
            print(a,'+',b,'=','几')
            ans=int(input())
            if ans==e:
                print('对了')
            else:
                print('不对')    
        elif c==2:
            e=a-b
            print(a,'-',b,'=','几')
            ans=int(input())
            if ans==e:
                print('对了')
            else:
                print('不对')
        elif c==3:
            e=a*b
            print(a,'*',b,'=','几')
            ans=int(input())
            if ans==e:
                print('对了')
            else:
                print('不对')
        else:
            print(a,'/',b,'=','几')
            e=a/b
            ans=float(input())
            if ans==e:
                print('对了')
            else:
                print('不对')
    
    

    望采纳

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 3月30日
  • 已采纳回答 3月22日
  • 创建了问题 3月22日

悬赏问题

  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。
  • ¥20 CST怎么把天线放在座椅环境中并仿真
  • ¥15 任务A:大数据平台搭建(容器环境)怎么做呢?
  • ¥15 YOLOv8obb获取边框坐标时报错AttributeError: 'NoneType' object has no attribute 'xywhr'