+ 1

Help with Python Functions RPS

https://code.sololearn.com/c8a242A14A11 ^^^^^^^^^^^ Here is my code so far I'm just starting to learn functions I like how the code functions so far but I need to display each round show the comp and human choice and then display a score board after each round until the desired amount of rounds are complete and then at the end display game over + the winner and then at the very bottom play again Y for yes Q for quit like this we will pretend that the user selected to play 2 rounds ROUND 1 of 2 ------------------ [Choose Rock, Paper or Scissors] >Enter choice: rock ------------------------------------------------------ ** You picked ROCK, I picked PAPER, I win! ** ------------------------------------------------------ <SCOREBOARD> ---------------------- Computer: 1 You: 0 ROUND 2 of 2 [Choose Rock, Paper or Scissors] >Enter choice: PAPER ------------------------------------------------------ ** You picked PAPER, I picked SCISSORS, I win! ** ------------------------------------------------------ <SCOREBOARD> ---------------------- Computer: 2 You: 0 GAME OVER! I WIN Play again? Enter 'Y' for yes, 'Q' to quit game >>Q Goodbye!

26th Feb 2021, 6:31 PM
Gutz_X_73vEn
Gutz_X_73vEn - avatar
14 Answers
+ 2
let me see i revamped it all
26th Feb 2021, 11:10 PM
Gutz_X_73vEn
Gutz_X_73vEn - avatar
+ 2
hold on
26th Feb 2021, 11:10 PM
Gutz_X_73vEn
Gutz_X_73vEn - avatar
+ 2
so i took out all of the global variables and then i defined 2 functions and made a while loop
26th Feb 2021, 11:13 PM
Gutz_X_73vEn
Gutz_X_73vEn - avatar
+ 2
still have alot of cleaning up to do haha
26th Feb 2021, 11:15 PM
Gutz_X_73vEn
Gutz_X_73vEn - avatar
+ 2
i fixed the ascii art a bit too
26th Feb 2021, 11:26 PM
Gutz_X_73vEn
Gutz_X_73vEn - avatar
+ 1
ïżŒLooking at the code, you should not be using globalized variables so much. Functions are mainly meant to take an input and then do something with it, returning the output. Using global so much is dangerous and confusing. pass the values to the function that you want it to work with, then accept the returned result. functions are not so much like screwdrivers as they are like pie machines. chickens go in, pies come out. secondly, you do not need a separate array for each way to capitalize a string. you can just use a string’s lower() method to return a lowercase version. thirdly, you can put all the ASCII art at the beginning inside one triple-quote string to span multiple lines without breaking it up.
26th Feb 2021, 9:09 PM
Wilbur Jaywright
Wilbur Jaywright - avatar
+ 1
4: The first input call should be “press enter to start” because the user can press any key but they must also press enter to send the unused input and move the program forward. 5. do not import random every time the funComputer() function runs. import the module once at the start of the program. 6. funMain ends up calling itself in success or faliure to get an input, and there is no way to stop this. funMain will call itself forever, and python will throw a max recursion depth call.
26th Feb 2021, 9:16 PM
Wilbur Jaywright
Wilbur Jaywright - avatar
+ 1
7. funRandom does not globalize anything, so it is just working within itself, and the computer’s choice remains unchanged. however, the call to this function was thankfully already commented out before you got here. Summary: I think you should do a complete overhaul on the code, starting almost from scratch. keep the if chain that checks for the winner, as that is tedious to rewrite, but maybe change the first letters of all the strings to lowercase.
26th Feb 2021, 9:23 PM
Wilbur Jaywright
Wilbur Jaywright - avatar
+ 1
so yeah it looks like i just need to figure out how to display the winner at game over when the count reaches numRounds and then i need to figure out how to break them back to the beginning if they choose “y” to play again right now i have them getting sent to the Choose_Option() but that way they cant re enter how many rounds to play and the count doesnt reset
27th Feb 2021, 12:22 AM
Gutz_X_73vEn
Gutz_X_73vEn - avatar
+ 1
I recommend using a pre-scripting program layout. Basically, write the layout of the program as if you were writing instructions for the game. But instead of so much trying to make a person understand it, write it as a series of steps like code would be. When you look over it, if anything seems to not be broken down enough, break it down more.
27th Feb 2021, 2:30 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
+ 1
SPOILER ALERT. tips for operation: when I learn python, the teacher who taught me used a system of menus. in a while loop that would check if the choice was “0” (meaning exit), he would have if statements for each possible choice, each choice being a number. for example: choice=“” while choice!=“0”: if choice==“1”: #option one elif choice==“2”: #option two elif choice: #There is an entry, but it is invalid print(“Invalid choice.”) print(“”” My program 0–EXIT 1–option one 2–option two”””) choice=input(“Choice: “)
27th Feb 2021, 2:35 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
0
SPOILER ALERT. More tips: I am thinking that there should be a main while loop with the option system mentioned above for the “keep playing or quit” menu system, and then inside of that there is a for loop that iterates over range(numRounds). if, within a game the user decides to quit, you can use the break keyword to stop the for loop. The program logic will probably end up printing the final score anyway, but I don’t think this is a problem. Then, the code will go back out to the while loop, and the user can restart with another game, or simply exit.
27th Feb 2021, 2:38 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
0
SPOILER ALERT. PS: you might be able to put the for loop within a function that excepts the number of rounds as an argument, and then returns (compWins, playerWins), or returns None if the game was cancelled.
27th Feb 2021, 2:39 AM
Wilbur Jaywright
Wilbur Jaywright - avatar
0
SPOILER ALERT. I guess the last thing in that case would be the recursion problem with getting a valid move. you could use a while loop that checks if the input is both not blank and in the valid choices, and further has an if statement inside it that checks the same thing but with a not and says “invalid choice” if it is invalid. you could even use index slicing to take the first letter of the input, so it will accept whole words.
27th Feb 2021, 2:45 AM
Wilbur Jaywright
Wilbur Jaywright - avatar