Jan-10-2020, 07:14 AM
(This post was last modified: Jan-10-2020, 07:14 AM by sandeep_ganga.)
Try this to see if it helps,
#lower() to be applied for the input taken variables, not on right hand side of comparing text.
(eg: player_1.lower() == 'paper':)
#None, because, assume rock, paper given, it first match main elif block, then it only have if block, it fail compare to scissors and thus looks for else or elif inside the main elif , found nothing and closing main elif and returning None with statemtnt print(play(p_1, p_2)) as none of if/elif/else got match return though elif block sucessful with p_!, but exited as no catch of p_2 string, i guess.
#tryagain code, you took input yes but no block/function defined to repeat taking inputs for re-run.
#elif conditions were looking little complex, may be you can try like,
Sandeep
GANGA SANDEEP KUMAR
items=['paper','scissors','rock']# items list i=True while i==True: #read strings , convert lower p_1=input("\nenter player 1 choice: ").lower() p_2=input("enter player 2 choice: ").lower() if (p_1 != p_2) and (p_1 in items) and (p_2 in items):# verify not same and given input are in list-items if (p_1=="rock" and p_2=="scissors") or (p_1=="paper" and p_2=="rock") or (p_1=="scissors" and p_2=="paper"):#player 1 win criteria print(f"{p_1} beats {p_2} , player 1 win!") else: print(f"{p_2} beats {p_1} , player 2 win!") #play again? yes/not playagain=input("play again: (yes/no) : " ).lower() if playagain == "yes": i=True else: i=False # stop while loop else: print(f"bad input/same words, {p_1,p_2} retrying game ") pass
Output:python test1.py
enter player 1 choice: ROck
enter player 2 choice: PAPER
paper beats rock , player 2 win!
play again: (yes/no) : yes
enter player 1 choice: rock
enter player 2 choice: scissors
rock beats scissors , player 1 win!
play again: (yes/no) : yes
enter player 1 choice: paper
enter player 2 choice: SCISSORS
scissors beats paper , player 2 win!
play again: (yes/no) : yes
enter player 1 choice: paper
enter player 2 choice: rock
paper beats rock , player 1 win!
play again: (yes/no) : yes
enter player 1 choice: scissors
enter player 2 choice: paper
scissors beats paper , player 1 win!
play again: (yes/no) : yes
enter player 1 choice: scissors
enter player 2 choice: rock
rock beats scissors , player 2 win!
play again: (yes/no) : yes
enter player 1 choice: rock
enter player 2 choice: ROCK
bad input/same words, ('rock', 'rock') retrying game
enter player 1 choice: rrr
enter player 2 choice: ttt
bad input/same words, ('rrr', 'ttt') retrying game
enter player 1 choice: rock
enter player 2 choice: paper
paper beats rock , player 2 win!
play again: (yes/no) : no
Few observations on your code, #lower() to be applied for the input taken variables, not on right hand side of comparing text.
(eg: player_1.lower() == 'paper':)
#None, because, assume rock, paper given, it first match main elif block, then it only have if block, it fail compare to scissors and thus looks for else or elif inside the main elif , found nothing and closing main elif and returning None with statemtnt print(play(p_1, p_2)) as none of if/elif/else got match return though elif block sucessful with p_!, but exited as no catch of p_2 string, i guess.
#tryagain code, you took input yes but no block/function defined to repeat taking inputs for re-run.
#elif conditions were looking little complex, may be you can try like,
elif player_1.lower() == 'rock': if player_2.lower() == 'scissors': return "Rock hits scissors. Player 1 win!" elif player_2.lower() == 'paper': return "Paper covers rock. Player 2 wins!" elif player_1.lower() == 'paper': if player_2.lower() == 'scissors': return "Scissors cut paper. Player 2 wins" elif player_2.lower() == 'rock': return "Paper covers rock. Player 1 wins!" elif player_1.lower() == 'scissors': if player_2.lower() == 'rock': return "Rock hits scissors. Player 2 wins!" elif player_2.lower() == 'paper': return "Scissors cut paper. Player 1 wins!"Best Regards,
Sandeep
GANGA SANDEEP KUMAR