-1
total_guess = 0
wins = 0
loss = 0
import random
characters = ["rock", "paper", "scissors", "lizard", "spock"]
computer = characters[random.randint(0,4)]
print(computer)

Subroutine- functions fine

def valid(text, flag):
    error_message= ""
    while True:
        var = input(error_message + text)
        if flag == "s":
            if var.isalpha()==True:
                break
            else:
               error_message = "This is not valid, "
        elif flag =="i":

            if var.isdigit()==True:
                var = int(var)
                break
            else:
                error_message = user_name + " this is not a number, "

        elif flag == "g":
            if var == "rock" or var == "paper" or var == "scissors" or var ==  "lizard" or var == "spock":
                break
            else:
                error_message = user_name + " this is not valid! "
    return(var)

user_name = valid("What is your name?", "s")
num_rounds = valid(user_name +" how many rounds do you want?", "i")

This code does not work either due to past changes initially worked, 'says can't convert 'int' object to str implicitly

while True:

        player = valid(user_name + """ ,What do you want as your character:
             Rock, paper, scissors, lizard or spock""", "g" )


        while num_rounds > total_guess:
            total_guess = total_guess + 1
            if player == computer:
                print("Draw!")
        #             --------------------------------------------
            elif player == "Rock" or player == "rock":
                if computer == "paper" or computer == "spock" :
                    loss = loss + 1
                    print("You lost ", computer, " beats ", player)
                    print( user_name + " you have won " + wins +" games")

                if computer == "scissors" or computer == "lizard":
                    wins = wins + 1
                    print("You win", player, " beats ", computer)

        #            ---------------------------------------------
            elif player == "Paper" or player == "paper":
                if computer == "scissors" or computer == "lizard":
                    loss = loss + 1
                    print("You lost ", computer, " beats ", player)


                if computer == "rock" or computer == "spock":
                    wins = wins + 1
                    print("You win", player, " beats ", computer)
        #            ---------------------------------------------
            elif player == "Scissors" or player == "scissors":
                if computer =="Spock" or computer == "rock":
                    loss = loss + 1
                    print("You lost ", computer, " beats ", player)


                if computer  =="paper" or computer == "lizard":
                    wins = wins + 1
                    print("You win", player, " beats ", computer)


        #             --------------------------------------------

            elif player == "Lizard" or  player =="lizard":
                if computer =="scissors" or computer == "rock":
                    loss = loss + 1
                    print("You lost ", computer, " beats ", player)


                if computer  == "paper" or computer == "spock":
                    wins = wins + 1
                    print("You win", player, " beats ", computer)


        #             --------------------------------------------
            elif player == "Spock" or player == "spock":
                if computer == "lizard" or computer == "paper":
                   loss = loss + 1
                   print("You lost ", computer, " beats ", player)

                if computer  =="rock" or computer == "scissors":
                    wins = wins + 1
                    print("You win", player, " beats ", computer)


    #             -------------------------------------------

This block code to restart game does not work it's purpose is to have a try again feature

        end_game = input("To exit enter N, to play again enter any key ")
        if end_game == 'n' or end_game == 'N':
                print("THANKS FOR PLAYING " + user_name + '!')
                break
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
jmes13
  • 11
  • 1
  • What line is the error on? Use `str(integer_here)` to convert to string – Andrew Li Sep 05 '16 at 00:46
  • line 65 print( user_name + " you have won " + wins +" games"), I believe this is for all of them – jmes13 Sep 05 '16 at 00:48
  • it was working initially when the while true was not present but since I need the retry ability I needed the while true – jmes13 Sep 05 '16 at 00:49
  • Could you post the entire code db in one chunk please – TheLazyScripter Sep 05 '16 at 00:49
  • @jmes13 What exactly is your question? Sorry, but I can't tell. – Christian Dean Sep 05 '16 at 00:49
  • 1
    And the error you are receiving is due to the fact that you are trying to concatenate a `str` and an `int`. I would recommend using `print(' '.join(( user_name, " you have won ", wins, " games")))` or `print(user_name + " you have won " + str(wins) + str(games))` it's up to you but I will tell you that `.join()` is faster. – TheLazyScripter Sep 05 '16 at 00:53
  • @TheLazyScripter that is my entire code – jmes13 Sep 05 '16 at 00:57
  • @TheLazyScripter can you edit my code for it to be functional – jmes13 Sep 05 '16 at 00:59
  • @jmes13 Is your entire code here and in order? – TheLazyScripter Sep 05 '16 at 01:13
  • player = valid (result + '\n' + " Rounds left: " + str(num_rounds) + '\n' " Games won: " + str(wins) + '\n' " Game drew: " + str(draw) + '\n' + user_name + " ,What do you want as your character: " + " Rock, paper, scissors, lizard or spock", "g" ) – jmes13 Sep 05 '16 at 22:31
  • the input is turned to dots need help on that – jmes13 Sep 05 '16 at 22:31
  • Voting to delete because this isn't remotely close to a [mre] and the title does not help with finding the canonical duplicate. – Karl Knechtel Jul 27 '22 at 03:25

1 Answers1

0

This could be shortened heavily but I don't feel like rewriting your entire program. This should work as expected.

total_guess = 0
wins = 0
loss = 0
import random
characters = ["rock", "paper", "scissors", "lizard", "spock"]
computer = characters[random.randint(0,4)]
print(computer)

def valid(text, flag):
    error_message= ""
    while True:
        var = input(error_message + text)
        if flag == "s":
            if var.isalpha()==True:
                break
            else:
               error_message = "This is not valid, "
        elif flag =="i":

            if var.isdigit()==True:
                var = int(var)
                break
            else:
                error_message = user_name + " this is not a number, "

        elif flag == "g":
            if var == "rock" or var == "paper" or var == "scissors" or var ==  "lizard" or var == "spock":
                break
            else:
                error_message = user_name + " this is not valid! "
    return(var)

user_name = valid("What is your name?", "s")
num_rounds = valid(user_name +" how many rounds do you want?", "i")

while True:
        while num_rounds > total_guess:
            player = valid(user_name + """ ,What do you want as your character:
             Rock, paper, scissors, lizard or spock""", "g" )
            total_guess = total_guess + 1
            if player == computer:
                print("Draw!")
        #             --------------------------------------------
            elif player == "Rock" or player == "rock":
                if computer == "paper" or computer == "spock" :
                    loss = loss + 1
                    print(' '.join(("You lost", computer, "beats", player)))

                if computer == "scissors" or computer == "lizard":
                    wins = wins + 1
                    print(' '.join(("You win", player, "beats", computer)))

            elif player == "Paper" or player == "paper":
                if computer == "scissors" or computer == "lizard":
                    loss = loss + 1
                    print(' '.join(("You lost", computer, "beats", player)))

                if computer == "rock" or computer == "spock":
                    wins = wins + 1
                    print(' '.join(("You win", player, "beats", computer)))

            elif player == "Scissors" or player == "scissors":
                if computer =="Spock" or computer == "rock":
                    loss = loss + 1
                    print(' '.join(("You lost", computer, " beats ", player)))

                if computer  =="paper" or computer == "lizard":
                    wins = wins + 1
                    print(' '.join(("You win", player, "beats", computer)))

            elif player == "Lizard" or  player =="lizard":
                if computer =="scissors" or computer == "rock":
                    loss = loss + 1
                    print(' '.join(("You lost", computer, "beats", player)))


                if computer  == "paper" or computer == "spock":
                    wins = wins + 1
                    print(' '.join(("You win", player, "beats", computer)))

            elif player == "Spock" or player == "spock":
                if computer == "lizard" or computer == "paper":
                   loss = loss + 1
                   print(' '.join(("You lost", computer, "beats", player)))

                if computer  =="rock" or computer == "scissors":
                    wins = wins + 1
                    print(' '.join(("You win", player, "beats", computer)))

        end_game = input("To exit enter N, to play again enter any key ")
        if end_game == 'n' or end_game == 'N':
            print("THANKS FOR PLAYING " + user_name + '!')
            break
        total_guess = 0
TheLazyScripter
  • 2,541
  • 1
  • 10
  • 19