猿问

我正在尝试用 python 编写一个简单的程序,但我卡住了

我正在尝试在 中制作一个非常简单的程序python,但它在错误窗口中显示语法无效。我无法理解它有什么问题:


print('What is your name?')

YourName = input()

if YourName == "Alice":

    print('Hello Alice')

elif print('How old are you?')

    age = input()

elif age < 4:

        print('And you know how to write at young age!')


茅侃侃
浏览 117回答 2
2回答

德玛西亚99

试试这个:print('What is your name?')YourName = input()if YourName == "Alice":&nbsp; &nbsp; print('Hello Alice')else:&nbsp; &nbsp; print('How old are you?')&nbsp; &nbsp; age = int(input())&nbsp; &nbsp; if age < 4:&nbsp; &nbsp; &nbsp; &nbsp; print('And you know how to write at young age!')和一个单线:print("Hello Alice") if input("What is your name ")=="Alice" else print('And you know how to write at young age!') if int(input("How old are you? "))<4 else None

蝴蝶不菲

你的代码有问题欢迎!以下行是错误的:elif print('How old are you?')这背后有两个主要原因:print('How old are you?')不是正常情况。尽管这在技术上很好,因为您的编译器会将其评估为类型None并将其视为 ,但False您可能希望用概念上有意义的内容替换该部分。你在elif.之后缺少一个冒号。例如:elif (int(input()) < 4):&nbsp; &nbsp; #your code解决方案print('What is your name?')YourName = input()if YourName == "Alice":&nbsp; &nbsp; print('Hello Alice')else:&nbsp; &nbsp; print('You are not Alice! How old are you?')&nbsp; &nbsp; if int(input()) < 4:&nbsp; &nbsp; &nbsp; &nbsp; print('You know how to write at young age!')
随时随地看视频慕课网APP

相关分类

Python
我要回答