[英]I'm trying to make a simple story maker but I'm stuck on the gender part
[英]I'm trying to make a simple program in python, but im stuck
我正在嘗試使用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!')
嘗試這個:
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
歡迎! 以下行是錯誤的:
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!')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.