HS514 2022-02-23 12:55 采纳率: 68.8%
浏览 22
已结题

这段代码为啥要输出两次

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
prompt = "Please tell me something,and I will repeat it to you:\n"
prompt += "If you enter'quit',you will end the program.\n"
while True:
    if input(prompt) != 'quit':
        print(input(prompt))

    else:
        break

Please tell me something,and I will repeat it to you:
If you enter'quit',you will end the program.
a
Please tell me something,and I will repeat it to you:
If you enter'quit',you will end the program.
aa
aa
Please tell me something,and I will repeat it to you:
If you enter'quit',you will end the program.
s
Please tell me something,and I will repeat it to you:
If you enter'quit',you will end the program.
ss
ss
Please tell me something,and I will repeat it to you:
If you enter'quit',you will end the program.


  • 写回答

2条回答 默认 最新

  • 於黾 2022-02-23 13:07
    关注

    print(input(prompt))
    这是在玩啥呢
    你前面不把input的内容先保存起来,后面print
    而是用于判断是否是quit,后面用户必须再次输入一个内容,然后输出这个内容

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

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 2月23日
  • 已采纳回答 2月23日
  • 创建了问题 2月23日

悬赏问题

  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)