一个简单的Python程序,用户输入“Heads”或“Tails”

时间:2017-07-05 14:33:25

标签: python

我尝试创建一个简单的Python程序,用户输入他们选择的硬币,头或尾的一面。我尝试运行它,但输出始终是“可悲的是,这不是正确的一面!”。有人可以告诉我如何改进这段代码吗?

import random

print ("Pick a side of the coin. Heads or Tails?")
input_coin = input()
input_coin = input_coin.lower
coin = random.choice(["heads", "tails"])

if input_coin == coin:
    print ("You picked the right side!")
else:
    print ("Sadly, that is not the right side!")

1 个答案:

答案 0 :(得分:13)

由于str是str内部的方法,因此应将其称为N x 500

的方法

而不是:

()

型:

 input_coin = input_coin.lower

正如Baldrickk评论的那样,你可以用一行代替两行:

input_coin = input_coin.lower()

如果您输入:input_coin = input().lower()

您将获得:print (input_coin.lower)

这不是你所期望的。

为了执行该方法,您需要用括号调用它。