Reputation: 9
I am trying to code a sort of walking on the ledge random chance game, users would input a certain amount they would like to bet and then depending on how many steps they would take, they would either live or fall off the ledge. The code so far is FAR from being finished but I have encountered a problem and I was wondering if someone could help me fix it.
import time
import random
class Player():
def __init__(self,name):
self.name = name
self.luck = 2
self.gold = 10
def main():
print("Hello what is your name?")
option = input("--> ")
global PlayerIG
PlayerIG = Player(option)
start1()
def start1():
print("Name: {}".format(PlayerIG.name))
print("Luck: {}".format(PlayerIG.luck))
print("Gold: {}".format(PlayerIG.gold))
inputgold()
def inputgold():
print("Please input how much gold you would like to play with")
goldinput = input("--> ")
strgold = str(goldinput)
print("You inputted {}".format(strgold))
if strgold <= PlayerIG.gold:
print("You don't have enough gold")
inputgold()
else:
print("Get ready to start!")
ledge()
def ledge():
print("You are standing on a ledge with an unknown length")
time.sleep(1)
choice = input("How many steps do you want to take forward? Between 1-100")
if choice == step1:
print("You have fallen off the ledge")
PlayerIG.gold -= goldinput
print("Gold: ".format(PlayerIG.gold))
elif choice == step2:
print("You...")
time.sleep(1)
print("Didn't fall off the ledge!")
PlayerIG.gold*1.2
print("Gold: ".format(PlayerIG.gold))
else:
print("You slipped off the ledge and face planted onto the side walk")
PlayerIG.gold -= goldinput
print("Gold: ".format(PlayerIG.gold))
def steps():
step1 = random.randint(10,30)
step2 = random.randint(30,50)
step3 = random.randint(50,100)
main()
When I run it is says:
if strgold <= PlayerIG.gold: TypeError: unorderable types: str() <= int()
How can I fix it?
Upvotes: 1
Views: 74
Reputation: 1333
The problem is this line:
if strgold <= PlayerIG.gold:
Here you are comparing a string with an integer. This is not possible, you have to convert the string to an integer first:
if int(strgold) <= PlayerIG.gold:
I haven't checked the rest of your code, but I suspect you might also have similar mistakes elsewhere too.
Upvotes: 1