程序的要點是詢問用戶的名字(自動大寫第一個字母)。新手卡住,容易「同時」在Python中重複
然後它會詢問年齡和性別。如果年齡超過130或負數,它會拋出一個錯誤
該程序應該打印出所有的信息,但我無法弄清楚while循環條件。任何人都可以幫我弄清楚while循環的條件嗎?
-edit-雖然Pastebin的鏈接已被編輯出來,但我認爲那裏有重要的信息。所以,我還是會給你的鏈接: http://pastebin.com/UBbXDGSt
name = input("What's your name? ").capitalize()
age = int(input("How old are you "))
gender = input("From what gender are you? ").capitalize()
while #I guess I should write something behind the "while" function. But what?
if age >= 130:
print("It's impossible that you're that old. Please try again!")
elif age <= 0:
print('''It should be logical that ages are written in positive numbers! Well, try again! =)''')
age = int(input("How old are you? "))
print("Your name is ",name, ". You are ", age, "years old." "\nYou are ", gender, ".")
什麼讓你覺得在這裏需要一個循環,你期待什麼發生? –
你不需要一個while循環。 if語句就足夠了。 –
我認爲目標是要求用戶的年齡**,而**他們輸入了無效值,直到他們輸入了有效的值。 –