我正在尝试撰写文字冒险。一开始,它询问一个人是男性还是女性。如果他们输入“男性”,我希望它使用他,他和他的话。如果他们输入“女性”,我希望它使用她和她等词。
print ("Is that person male or female?")
gender = input ()
if gender == "male":
1 = his
2 = he
3 = him
else:
1 = her
2 = she
3 = her
我希望在输入数字时显示单词:
print (2,"went with", 3,)
这应该说"he went with him"
或"she went with her"
,但事实并非如此。
答案 0 :(得分:1)
gender = input("Is that person male or female? ")
if gender == "male":
one = "his"
two = "he"
three = "him"
else:
one = "her"
two = "she"
three = "her"
print(one+' item that '+two+' had was for '+three)
这是它的外观示例。
答案 1 :(得分:0)
Python变量名称规则:
- 必须以字母(a - z,A - B)或下划线(_)
开头- 其他字符可以是字母,数字或_
- 区分大小写
- 可以是任何(合理的)长度
- 有一些保留字不能用作变量名,因为Python将它们用于其他事情。
醇>
来自here