我正在尝试在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!')
答案 0 :(得分:2)
尝试一下:
print('What is your name?')
YourName = input()
if YourName == "Alice":
print('Hello Alice')
else:
print('How old are you?')
age = int(input())
if age < 4:
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
答案 1 :(得分:1)
欢迎光临!以下行是错误的:
elif print('How old are you?')
这背后有两个主要原因:
print('How old are you?')
不是正常情况。尽管从技术上讲这很好,因为编译器会将其评估为None
类型,并将其视为False
,但是您可能希望用概念上有意义的东西替换该部分。在elif
之后,您丢失了一个冒号。例如:
elif (int(input()) < 4):
#your code
print('What is your name?')
YourName = input()
if YourName == "Alice":
print('Hello Alice')
else:
print('You are not Alice! How old are you?')
if int(input()) < 4:
print('You know how to write at young age!')