Skip to main content
Tweeted twitter.com/StackCodeReview/status/753187336331137024
Edit tags;
Source Link
Peilonrayz
  • 44.6k
  • 7
  • 80
  • 158

Recently I started programming with python. Today I was trying to make a stone, paper, scissor game. After so scratching my head long time, Finallyfinally I got a working code.

from random import choice

from random import choice

def play_again():
        print "Do you want to play again:- Choose 'yay' or 'nay'"
        user_again = raw_input('->')
        if user_again == 'yay':
            SPCa()
        elif user_again == 'nay':
            print "Ok bye! hope you enjoyed the game. See you soon! :)"
        else:
            print "Please choose correct option."
            play_again()


def SPCa():
    computer_choice = choice( ['stone', 'paper', 'scissor'] )
    computer_choosed =  "Computer choosed %s" % computer_choice
    print "Make an choice"
    print "Choose stone, paper, scissor"
    user_choice = raw_input('->')

    if user_choice == computer_choice:
        print computer_choosed
        print "So it's a tie"
        play_again()

    elif user_choice == 'stone':
        if computer_choice == 'paper':
            print computer_choosed
            print "So, You loose"
            play_again()
        elif computer_choice == 'scissor':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()

    elif user_choice == 'paper':
        if computer_choice == 'scissor':
            print computer_choosed
            print "So, you loose."
           play_again()
        elif computer_choice == 'stone':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()

   elif user_choice == 'scissor':
        if computer_choice == 'stone':
            print computer_choosed
            print "So, you loose."
            play_again()
        elif computer_choice == 'paper':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()
    else:  
         print "please choose correct option"
        SPCa()
    
    
def SPC():
    computer_choice = choice( ['stone', 'paper', 'scissor'] )
    computer_choosed =  "Computer choosed %s" % computer_choice
    print "You are playing Stone, Paper, Scissor."
    print "Make an choice"
    print "Choose stone, paper, scissor"
    user_choice = raw_input('->')

    if user_choice == computer_choice:
        print computer_choosed
        print "So it's a tie"
        play_again()
    
   elif user_choice == 'stone':
        if computer_choice == 'paper':
            print computer_choosed
            print "So, You loose"
            play_again()
        elif computer_choice == 'scissor':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()

    elif user_choice == 'paper':
        if computer_choice == 'scissor':
            print computer_choosed
            print "So, you loose."
            play_again()
        elif computer_choice == 'stone':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()

    elif user_choice == 'scissor':
        if computer_choice == 'stone':
            print computer_choosed
            print "So, you loose."
            play_again()
        elif computer_choice == 'paper':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()
    else:
        print "please choose correct option"
        SPCa()
SPC()

But I found my code so repetitive, it has not even a single a loop. Please suggest how can I improve my code. What are things that iI should learn?

Recently I started programming with python. Today I was trying to make a stone, paper, scissor game. After so scratching my head long time, Finally I got a working code.

from random import choice

def play_again():
        print "Do you want to play again:- Choose 'yay' or 'nay'"
        user_again = raw_input('->')
        if user_again == 'yay':
            SPCa()
        elif user_again == 'nay':
            print "Ok bye! hope you enjoyed the game. See you soon! :)"
        else:
            print "Please choose correct option."
            play_again()


def SPCa():
    computer_choice = choice( ['stone', 'paper', 'scissor'] )
    computer_choosed =  "Computer choosed %s" % computer_choice
    print "Make an choice"
    print "Choose stone, paper, scissor"
    user_choice = raw_input('->')

    if user_choice == computer_choice:
        print computer_choosed
        print "So it's a tie"
        play_again()

    elif user_choice == 'stone':
        if computer_choice == 'paper':
            print computer_choosed
            print "So, You loose"
            play_again()
        elif computer_choice == 'scissor':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()

    elif user_choice == 'paper':
        if computer_choice == 'scissor':
            print computer_choosed
            print "So, you loose."
           play_again()
        elif computer_choice == 'stone':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()

   elif user_choice == 'scissor':
        if computer_choice == 'stone':
            print computer_choosed
            print "So, you loose."
            play_again()
        elif computer_choice == 'paper':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()
    else:  
         print "please choose correct option"
        SPCa()
    
    
def SPC():
    computer_choice = choice( ['stone', 'paper', 'scissor'] )
    computer_choosed =  "Computer choosed %s" % computer_choice
    print "You are playing Stone, Paper, Scissor."
    print "Make an choice"
    print "Choose stone, paper, scissor"
    user_choice = raw_input('->')

    if user_choice == computer_choice:
        print computer_choosed
        print "So it's a tie"
        play_again()
    
   elif user_choice == 'stone':
        if computer_choice == 'paper':
            print computer_choosed
            print "So, You loose"
            play_again()
        elif computer_choice == 'scissor':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()

    elif user_choice == 'paper':
        if computer_choice == 'scissor':
            print computer_choosed
            print "So, you loose."
            play_again()
        elif computer_choice == 'stone':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()

    elif user_choice == 'scissor':
        if computer_choice == 'stone':
            print computer_choosed
            print "So, you loose."
            play_again()
        elif computer_choice == 'paper':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()
    else:
        print "please choose correct option"
        SPCa()
SPC()

But I found my code so repetitive, it has not even a single a loop. Please suggest how can I improve my code. What are things that i should learn?

Recently I started programming with python. Today I was trying to make a stone, paper, scissor game. After so scratching my head long time, finally I got a working code.

from random import choice

def play_again():
        print "Do you want to play again:- Choose 'yay' or 'nay'"
        user_again = raw_input('->')
        if user_again == 'yay':
            SPCa()
        elif user_again == 'nay':
            print "Ok bye! hope you enjoyed the game. See you soon! :)"
        else:
            print "Please choose correct option."
            play_again()


def SPCa():
    computer_choice = choice( ['stone', 'paper', 'scissor'] )
    computer_choosed =  "Computer choosed %s" % computer_choice
    print "Make an choice"
    print "Choose stone, paper, scissor"
    user_choice = raw_input('->')

    if user_choice == computer_choice:
        print computer_choosed
        print "So it's a tie"
        play_again()

    elif user_choice == 'stone':
        if computer_choice == 'paper':
            print computer_choosed
            print "So, You loose"
            play_again()
        elif computer_choice == 'scissor':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()

    elif user_choice == 'paper':
        if computer_choice == 'scissor':
            print computer_choosed
            print "So, you loose."
           play_again()
        elif computer_choice == 'stone':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()

   elif user_choice == 'scissor':
        if computer_choice == 'stone':
            print computer_choosed
            print "So, you loose."
            play_again()
        elif computer_choice == 'paper':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()
    else:  
         print "please choose correct option"
        SPCa()
    
    
def SPC():
    computer_choice = choice( ['stone', 'paper', 'scissor'] )
    computer_choosed =  "Computer choosed %s" % computer_choice
    print "You are playing Stone, Paper, Scissor."
    print "Make an choice"
    print "Choose stone, paper, scissor"
    user_choice = raw_input('->')

    if user_choice == computer_choice:
        print computer_choosed
        print "So it's a tie"
        play_again()
    
   elif user_choice == 'stone':
        if computer_choice == 'paper':
            print computer_choosed
            print "So, You loose"
            play_again()
        elif computer_choice == 'scissor':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()

    elif user_choice == 'paper':
        if computer_choice == 'scissor':
            print computer_choosed
            print "So, you loose."
            play_again()
        elif computer_choice == 'stone':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()

    elif user_choice == 'scissor':
        if computer_choice == 'stone':
            print computer_choosed
            print "So, you loose."
            play_again()
        elif computer_choice == 'paper':
            print computer_choosed
            print "So, Cheers! You won!"
            play_again()
    else:
        print "please choose correct option"
        SPCa()
SPC()

But I found my code so repetitive, it has not even a single loop. Please suggest how can I improve my code. What are things that I should learn?

deleted 29 characters in body
Source Link
BCdotWEB
  • 11.4k
  • 2
  • 28
  • 45

Thank you, for our help.

Thank you, for our help.

changed title to reflect what code *does*
Link
forsvarir
  • 11.8k
  • 7
  • 39
  • 72

what are the problems in my code Stone, Paper, Scissors in Python

Source Link
Loading