?887 2022-08-06 21:58 采纳率: 97.8%
浏览 71
已结题

python用while循环

img


a = int(input("Enter the first number: "))
b = int(input("Enter the second number: "))
if a > b:
i = a
while i < b+1:
print(i,end=" ")
i += 1
elif a < b:
i = b
while i <a+1:
print(i,end=" ")
i += 1
要求输入数字,然后按从大到小去排列数字,写出代码后输入数字,什么都输出不出来,也没有报错。

  • 写回答

5条回答 默认 最新

  • 关注

    你题目的解答代码如下:

    a = int(input("Enter the first number: "))
    b = int(input("Enter the second number: "))
    if a < b:   # 这里是 a < b
        i = a
        while i <= b:
            print(i,end=" ")
            i += 1
    elif a >= b:  # 这里是 a >= b
        i = b
        while i <= a:
            print(i,end=" ")
            i += 1
    

    如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!

    img


    ,

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 11月9日
  • 已采纳回答 11月1日
  • 创建了问题 8月6日

悬赏问题

  • ¥20 Keil编译时报错"no source": Error: #5: cannot open source
  • ¥50 操作系统时间无法更新
  • ¥20 Windows11, usb转hdmi,外接显示器无反应
  • ¥20 怎么在JavaFx的TableView中动态地添加数据。
  • ¥15 MFC里的工具栏按钮图标使用外部图片
  • ¥15 如何在 llama.cpp 服务器中实现用户登录功能的优化方案?(语言-c++)
  • ¥15 有会用octave 的吗,急!代做!好偿!
  • ¥15 有一套同城小程序源码,Uniapp前端,php+html+mysql后端 ,能不能教我搭建起来可以运行,我不知道怎样操作
  • ¥15 mac调用java.io接口无法在根目录生成文件
  • ¥15 java微服务节点假死,网关路由时长延迟