Python Forum
RockPaperScissor program while loop malfunction
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RockPaperScissor program while loop malfunction
#2
So, you want someone to code the rest of your game, basically just the part with money, because when I tried playing it, it seems fine. We're not supposed to do your homework for you, so all I can do is help you. First, make a load function that tries to load money from the file, and if not gives them a set amount like below.
def loadData():
    with open("playMoney.txt", "r") as saveFile:
        money = saveFile.read()
        if not money or money == 0:
            print("Renewing money")
            return #Default amount
        return money
All you need to do is make a money variable in the main function, use function arguments and returns to pass it back and forth between functions, whenever the player wins, give them money, else, take away some money, or on a tie, neither. Then when they quit or their money runs out, execute a save function that should look something like this.
def save(money):
    with open("playMoney.txt", "w") as saveFile:
        saveFile.write(money)
It shouldn't take you too long to add this on to the game. I don't believe I made a mistake with the save and load functions, but if there's an error that you can't figure out just post about it on this question.
Reply


Messages In This Thread
RE: RockPaperScissor program while loop malfunction - by SheeppOSU - Apr-03-2020, 10:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using If Statements Instead of While Loop in Simple Game Program new_coder_231013 5 3,254 Dec-14-2021, 12:23 AM
Last Post: supuflounder
  How to compile following python loop program reinispl 3 2,001 Oct-27-2021, 01:57 PM
Last Post: DeaD_EyE
  Program that, inside a loop, does multiple things. needs to print in a certain way reidmcleod 1 2,709 Feb-19-2019, 02:35 PM
Last Post: marienbad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020