A simple Python program into which the user types "Heads" or "Tails"
I tried to create a simple Python program where the user enters their choice towards coins, heads, or tails. I tried running it, but the output was consistently "Sorry, this is not the right side!". Can someone please tell me how to improve this code?
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!")
+3
source to share
1 answer
The below method is inside str, you have to call it like a method with ()
Instead:
input_coin = input_coin.lower
A type:
input_coin = input_coin.lower()
As Baldrickk commented, you can do it with one line instead of two:
input_coin = input().lower()
If you type: print (input_coin.lower)
You'll get: <built-in method lower of str object at 0x7f901b5c2378>
This is not what you expected, I think.
To execute a method, you need to call it using parentheses.
+13
source to share