Skip to main content
Became Hot Network Question
added 47 characters in body
Source Link
toolic
  • 6.4k
  • 4
  • 20
  • 79
import random
#1 = Rock, 2 = Paper, 3 = Scissors
random_number = random.randint(1,3)
try:
  input = int(input("1 for rock, 2 for paper, 3 for scissors: "))
except ValueError:
  print("You didn't enter a number. You lose.")

if input == random_number:
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Tie.")

elif (input==1 and random_number==2) or (input==2 and random_number==3) or (input==3 and random_number==1):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Lose.")

elif (input==1 and random_number==3) or (input==2 and random_number==1) or (input==3 and random_number==2):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:

        random_number = "Rock"
      elif random_number == 2:
        random_number = "Paper"
      else:
        random_number = "Scissors"
      print(f"You chose {input} and the computer chose {random_number}. You Win.") 
      
    else:
      if type(input) is int:
        print("You chose an invalid number. You Lose.")

This code should play rock paper scissorplays the "Rock, Paper, Scissors" game against the user. I was wondering how exactly should I handle my constantrepeated nesting. I am looking for more organized code.

import random
#1 = Rock, 2 = Paper, 3 = Scissors
random_number = random.randint(1,3)
try:
  input = int(input("1 for rock, 2 for paper, 3 for scissors: "))
except ValueError:
  print("You didn't enter a number. You lose.")

if input == random_number:
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Tie.")

elif (input==1 and random_number==2) or (input==2 and random_number==3) or (input==3 and random_number==1):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Lose.")

elif (input==1 and random_number==3) or (input==2 and random_number==1) or (input==3 and random_number==2):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:

        random_number = "Rock"
      elif random_number == 2:
        random_number = "Paper"
      else:
        random_number = "Scissors"
      print(f"You chose {input} and the computer chose {random_number}. You Win.") 
      
    else:
      if type(input) is int:
        print("You chose an invalid number. You Lose.")

This code should play rock paper scissor against the user. I was wondering how exactly should I handle my constant nesting.

import random
#1 = Rock, 2 = Paper, 3 = Scissors
random_number = random.randint(1,3)
try:
  input = int(input("1 for rock, 2 for paper, 3 for scissors: "))
except ValueError:
  print("You didn't enter a number. You lose.")

if input == random_number:
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Tie.")

elif (input==1 and random_number==2) or (input==2 and random_number==3) or (input==3 and random_number==1):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Lose.")

elif (input==1 and random_number==3) or (input==2 and random_number==1) or (input==3 and random_number==2):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:

        random_number = "Rock"
      elif random_number == 2:
        random_number = "Paper"
      else:
        random_number = "Scissors"
      print(f"You chose {input} and the computer chose {random_number}. You Win.") 
      
    else:
      if type(input) is int:
        print("You chose an invalid number. You Lose.")

This code plays the "Rock, Paper, Scissors" game against the user. I was wondering how exactly should I handle my repeated nesting. I am looking for more organized code.

edited tags; edited title
Source Link
toolic
  • 6.4k
  • 4
  • 20
  • 79

How can i fix my constant nesting Rock-paper-scissors game as a beginner?

import random
#1 = Rock, 2 = Paper, 3 = Scissors
random_number = random.randint(1,3)
try:
  input = int(input("1 for rock, 2 for paper, 3 for scissors: "))
except ValueError:
  print("You didn't enter a number. You lose.")

if input == random_number:
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Tie.")

elif (input==1 and random_number==2) or (input==2 and random_number==3) or (input==3 and random_number==1):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Lose.")

elif (input==1 and random_number==3) or (input==2 and random_number==1) or (input==3 and random_number==2):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:

        random_number = "Rock"
      elif random_number == 2:
        random_number = "Paper"
      else:
        random_number = "Scissors"
      print(f"You chose {input} and the computer chose {random_number}. You Win.") 
      
    else:
      if type(input) is int:
        print("You chose an invalid number. You Lose.")

This code should play rock paper scissor against the user. I was wonderwondering how exactly should I handle my constant nesting.

How can i fix my constant nesting as a beginner?

import random
#1 = Rock, 2 = Paper, 3 = Scissors
random_number = random.randint(1,3)
try:
  input = int(input("1 for rock, 2 for paper, 3 for scissors: "))
except ValueError:
  print("You didn't enter a number. You lose.")

if input == random_number:
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Tie.")

elif (input==1 and random_number==2) or (input==2 and random_number==3) or (input==3 and random_number==1):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Lose.")

elif (input==1 and random_number==3) or (input==2 and random_number==1) or (input==3 and random_number==2):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:

        random_number = "Rock"
      elif random_number == 2:
        random_number = "Paper"
      else:
        random_number = "Scissors"
      print(f"You chose {input} and the computer chose {random_number}. You Win.") 
      
    else:
      if type(input) is int:
        print("You chose an invalid number. You Lose.")

This code should play rock paper scissor against the user. I was wonder how exactly should I handle my constant nesting.

Rock-paper-scissors game as a beginner

import random
#1 = Rock, 2 = Paper, 3 = Scissors
random_number = random.randint(1,3)
try:
  input = int(input("1 for rock, 2 for paper, 3 for scissors: "))
except ValueError:
  print("You didn't enter a number. You lose.")

if input == random_number:
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Tie.")

elif (input==1 and random_number==2) or (input==2 and random_number==3) or (input==3 and random_number==1):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Lose.")

elif (input==1 and random_number==3) or (input==2 and random_number==1) or (input==3 and random_number==2):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:

        random_number = "Rock"
      elif random_number == 2:
        random_number = "Paper"
      else:
        random_number = "Scissors"
      print(f"You chose {input} and the computer chose {random_number}. You Win.") 
      
    else:
      if type(input) is int:
        print("You chose an invalid number. You Lose.")

This code should play rock paper scissor against the user. I was wondering how exactly should I handle my constant nesting.

deleted 21 characters in body
Source Link
Reinderien
  • 65.6k
  • 5
  • 70
  • 191
import random
#1 = Rock, 2 = Paper, 3 = Scissors
random_number = random.randint(1,3)
try:
  input = int(input("1 for rock, 2 for paper, 3 for scissors: "))
except ValueError:
  print("You didn't enter a number. You lose.")

if input == random_number:
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Tie.")

elif (input==1 and random_number==2) or (input==2 and random_number==3) or (input==3 and random_number==1):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Lose.")

elif (input==1 and random_number==3) or (input==2 and random_number==1) or (input==3 and random_number==2):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:

        random_number = "Rock"
      elif random_number == 2:
        random_number = "Paper"
      else:
        random_number = "Scissors"
      print(f"You chose {input} and the computer chose {random_number}. You Win.") 
      
    else:
      if type(input) is int:
        print("You chose an invalid number. You Lose.")

Blockquote This code should play rock paper scissor against the user. >I was wonder how exactly should I handle my constant nesting.

This code should play rock paper scissor against the user. I was wonder how exactly should I handle my constant nesting.

import random
#1 = Rock, 2 = Paper, 3 = Scissors
random_number = random.randint(1,3)
try:
  input = int(input("1 for rock, 2 for paper, 3 for scissors: "))
except ValueError:
  print("You didn't enter a number. You lose.")

if input == random_number:
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Tie.")

elif (input==1 and random_number==2) or (input==2 and random_number==3) or (input==3 and random_number==1):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Lose.")

elif (input==1 and random_number==3) or (input==2 and random_number==1) or (input==3 and random_number==2):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:

        random_number = "Rock"
      elif random_number == 2:
        random_number = "Paper"
      else:
        random_number = "Scissors"
      print(f"You chose {input} and the computer chose {random_number}. You Win.") 
      
    else:
      if type(input) is int:
        print("You chose an invalid number. You Lose.")

Blockquote This code should play rock paper scissor against the user. >I was wonder how exactly should I handle my constant nesting.

import random
#1 = Rock, 2 = Paper, 3 = Scissors
random_number = random.randint(1,3)
try:
  input = int(input("1 for rock, 2 for paper, 3 for scissors: "))
except ValueError:
  print("You didn't enter a number. You lose.")

if input == random_number:
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Tie.")

elif (input==1 and random_number==2) or (input==2 and random_number==3) or (input==3 and random_number==1):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:
    random_number = "Rock"
  elif random_number == 2:
    random_number = "Paper"
  else:
    random_number = "Scissors"
  print(f"You chose {input} and the computer chose {random_number}. You Lose.")

elif (input==1 and random_number==3) or (input==2 and random_number==1) or (input==3 and random_number==2):
  if input == 1:
    input = "Rock"
  elif input == 2:
    input = "Paper"
  else:
    input = "Scissors"
  if random_number == 1:

        random_number = "Rock"
      elif random_number == 2:
        random_number = "Paper"
      else:
        random_number = "Scissors"
      print(f"You chose {input} and the computer chose {random_number}. You Win.") 
      
    else:
      if type(input) is int:
        print("You chose an invalid number. You Lose.")

This code should play rock paper scissor against the user. I was wonder how exactly should I handle my constant nesting.

edited body
Source Link
LMays
  • 155
  • 5
Loading
Source Link
LMays
  • 155
  • 5
Loading