【问题标题】:Python input is requiring 3 lines [closed]Python输入需要3行[关闭]
【发布时间】:2020-08-07 03:11:52
【问题描述】:

为什么 python 要求我输入 3 次才能告诉我“你不是 Alice!”

print('What is your name')
input() #allows user to input their name
if input() == 'Alice':
    print('Hi, Alice. What is your age?')
age = input()
if age < 12:
    print('you are not Alice!')
elif age > 300:
    print ('unlike you, Alice isnt an undead, Immortal vampire')

【问题讨论】:

  • 你给input打了多少次电话?你对它提供给你的数据做了什么?
  • 不要多次使用input(),将第一个input()赋给一个变量
  • python 不需要你在这里做任何事情。这一切都是你自己做的
  • input() #allows user to input their name if input() == 'Alice': 您需要在此处输入您的姓名两次,因为您希望用户输入两次。

标签: python python-3.x loops input logic


【解决方案1】:

有几件事,你必须将input() 分配给一个变量,它不能像你在运行时那样完成,你必须确保缩进第二个if/elif in-lineage 输入。试试这个。

print('What is your name')
name = input() #allows user to input their name

if name == 'Alice':
   print('Hi, Alice. What is your age?')
   age = int(input())

   if age < 12:
     print('you are not Alice!')
   elif age > 300:
     print('unlike you, Alice isnt an undead, Immortal vampire')

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-19
    • 2012-12-11
    • 1970-01-01
    相关资源
    最近更新 更多