Ich versuche eine Art des Gehens auf dem Random-Zufallsspiel zu programmieren, Benutzer würden einen bestimmten Betrag eingeben, den sie gerne wetten würden und dann abhängig davon, wie viele Schritte sie nehmen würden, würden sie leben oder fallen von der Kante. Der Code ist bisher noch nicht fertig, aber ich habe ein Problem festgestellt und ich habe mich gefragt, ob mir jemand helfen könnte, das Problem zu beheben.Mein Python-Spielcode funktioniert nicht
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()
Wenn ich es laufen soll, sagt:
if strgold <= PlayerIG.gold: TypeError: unorderable types: str() <= int()
Wie kann ich es beheben?