Feb-28-2019, 08:02 PM
My isuue for code below is , my code stop working after validate . This is a game with two players and the computer , the score has to save by player name , the game will be 3 rounds. I would like to know why my selection for the menu is not working. Thank you
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
from random import randint Playernames = [] def validate(): while True : Player1 = input ( "what is the name of the first player : " ) Player2 = input ( "what is the name of the second player : " ) Playernames.append(Player1) Playernames.append(Player2) print (Player1, 'and' ,Player2) if len (Player1 and Player2) < 5 : print ( "Not valid ,please make sure your name is at least 5 letters" ) elif len (Player1 and Player2 ) > 20 : print ( "Make sure your name has less than 20 letters" ) else : break validate() while True : print ( "1.Play Game" ) print ( "2.Show Game Rules" ) print ( "3.Show Statistics" ) print ( "4.Exit" ) selection = input ( 'Please enter a selection:' ) if selection = = '1' : print ( 'player1' or 'player2' ) Play = eval ( input ( 'How many games of Rock-Paper-Scissors do you want to play?:' )) while ( 1 ): if (Play % 2 = = 0 ): # to check that number is not even Play = int ( input ( 'Please enter an odd number of games.:' )) else : break choice = [ "Rock" , "Paper" , "Scissors" , "Saw" ] computer = choice[randint( 0 , 3 )] player1 = = false player2 = = false while player1 and player2 = = false: player1_win = 0 # to count number of wins by user Player2_win = 0 # to count number of wins by user comp_win = 0 # to count number of wins by computer i = 0 player1 = input ( "Rock, Paper, Scissors, Saw?" ) if player1 = = computer: print ( "Tie!" ) elif player1 = = "Rock" : if computer = = "Paper" : print ( "You lose!" , computer, "covers" , player1) else : print ( "You win!" , player1, "smashes" , computer) elif player1 = = "Paper" : if computer = = "Scissors" : print ( "You lose!" , computer, "cut" , player1) else : print ( "You win!" , player1, "covers" , computer) elif player1 = = "Scissors" : if computer = = "Rock" : print ( "You lose..." , computer, "smashes" , player1) else : print ( "You win!" , player1, "cut" , computer) player2 = input ( "Rock, Paper, Scissors,Saw?" ) if player2 = = computer: print ( "Tie!" ) elif player2 = = "Rock" : if computer = = "Paper" : print ( "You lose!" , computer, "covers" , player2) else : print ( "You win!" , player2, "smashes" , computer) elif player = = "Paper" : if computer = = "Scissors" : print ( "You lose!" , computer, "cut" , player2) else : print ( "You win!" , player2, "covers" , computer) elif player = = "Scissors" : if computer = = "Rock" : print ( "You lose..." , computer, "smashes" , player2) else : print ( "You win!" , player2, "cut" , computer) |