【发布时间】:2017-01-11 20:25:36
【问题描述】:
这是一个简单的代码,脚本会询问用户的姓名、年龄、性别和身高,并根据这些信息给出输出。我目前的代码如下:
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)
我被 if、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”。我不知道如何获得“你低于平均水平”的回报。
【问题讨论】:
标签: python-2.7