0
這是一個簡單的代碼,腳本會詢問用戶的姓名,年齡,性別和身高,並根據該代碼給出輸出。我當前的代碼如下:Python;基於用戶輸入的打印輸出
print "What is your name?"
name = raw_input()
print "How old are you?"
age = raw_input()
print "Are you male? Please answer Y or N"
sex = raw_input()
if sex == "Y" or sex == "y":
sex = "Male"
else:
sex = "Female"
print "How tall are you? Please enter in feet such as 5.5"
height = raw_input()
if sex == "Male" and height >= 6.0:
t = "You are tall for a male"
elif sex == "Male" and height < 6.0:
t = "You are below average for a male"
elif sex == "Female" and height >= 5.5:
t = "You are tall for a female"
else:
t = "You are below average for a female"
print "Hello %s. You are %s years old and %s feet tall. %s." % (name, age, height, t)
我收到掛了,如果,elif的,else語句:
if sex == "Male" and height >= 6.0:
t = "You are tall for a male"
elif sex == "Male" and height < 6.0:
t = "You are below average for a male"
elif sex == "Female" and height >= 5.5:
t = "You are tall for a female"
else:
t = "You are below average for a female"
如果性別是男是女的代碼將分化,但總會迴歸「你爲xxx高個子」。我無法弄清楚如何得到「你低於平均水平」的回報。
這完美。謝謝! –