我似乎无法分配东西

时间:2016-06-09 15:51:13

标签: python python-3.x variables text

我正在尝试撰写文字冒险。一开始,它询问一个人是男性还是女性。如果他们输入“男性”,我希望它使用他,他和他的话。如果他们输入“女性”,我希望它使用她和她等词。

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",但事实并非如此。

2 个答案:

答案 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变量名称规则:

  
      
  1. 必须以字母(a - z,A - B)或下划线(_)
  2. 开头   
  3. 其他字符可以是字母,数字或_
  4.   
  5. 区分大小写
  6.   
  7. 可以是任何(合理的)长度
  8.   
  9. 有一些保留字不能用作变量名,因为Python将它们用于其他事情。
  10.   

来自here