I was just making a Rock , Paper and scissor game in python(Version 3.9 ) but whenever I try to run , there is NONE written at every input statement... My whole program works fine but I am really annoyed with "NONE" is there anything I am doing something wrong in my code. I will really appreciate your help!
Here is my code:
import random
num__round = int(input("Enter the number of rounds you want to play for: "))
rounds = 1
while rounds <= num__round:
comp_choices = ["Rock" , "Paper" , "Scissor"]
print("Round number", rounds)
user_action = str(input(print("Enter your choice from ===> Rock , Paper or Scissor"))).lower()
comp_actions = str(random.choice(comp_choices)).lower()
if user_action == comp_actions:
print("You Chose==>" , user_action , "Computer Chose ==>" , comp_actions , "\nRound draw\n")
elif user_action == 'rock':
if comp_actions == 'paper':
print("You Chose==>" , user_action , "\nComputer Chose ==>" , comp_actions)
print("Paper defeats rock!\n<===You lost this round===>,Computer won this round!\n")
else:
print("You Chose==>" , user_action , "\nComputer Chose ==>" , comp_actions)
print("Rock breaks scissor!\n<===You won this round!===>\n")
elif user_action == 'paper':
if comp_actions == 'rock':
print("You Chose==>" , user_action , "\nComputer Chose ==>" , comp_actions , "\n")
print("Paper defeats rock!\n<===You won this round===>,Computer lost!" , "\n")
else:
print("You Chose==>" , user_action , "\nComputer Chose ==>" , comp_actions)
print("Scissor torn the paper into pieces!\n<===You lost this round===>,Computer won!\n")
else:
if comp_actions == 'rock':
print("You Chose==>" , user_action , "\nComputer Chose ==>" , comp_actions )
print("Rock brutally breaks the scissor!\n<===You lost this round===>,Computer won\n")
else:
print("You Chose==>" , user_action , "\nComputer Chose ==>" , comp_actions)
print("Scissor torn down the paper!\n<===You won this round===>,Computer lost this
round!\n")
rounds = rounds 1
And here is the "None" written in every input statement:
Enter your choice from ===> Rock , Paper or Scissor None rock
CodePudding user response:
input
is willing to prompt your
"Enter your choice from ===> Rock , Paper or Scissor"
on its own but you also put a print
there. So first print
prints what you give it, and then its return value (print returns None
) is passed to input
and input
then prompts this None
(if you notice, it's on a newline actually because your print gave a newline).
So you dont need print
there:
user_action = str(input("Enter your choice from ===> Rock , Paper or Scissor")).lower()
More, you don't need to cast str
the input's result because it's always a string (if succeeds), so
user_action = input("Enter your choice from ===> Rock, Paper or Scissors: ").lower()
CodePudding user response:
I copied this myself and got the NONE to go away by moving the input().lower() out of the print statement
print("Enter your choice from ===> Rock , Paper or Scissor")
user_action = str(input()).lower()
comp_actions = str(random.choice(comp_choices)).lower()
CodePudding user response:
Simply remove the print()
from your input:
str(input("Enter your choice from ===> Rock , Paper or Scissor\n")).lower()
CodePudding user response:
whenever you see none its because your using print twice
change this:
user_action = str(input(print("Enter your choice from ===> Rock , Paper or Scissor"))).lower()
to this:
user_action = str(input("Enter your choice from ===> Rock , Paper or Scissor")).lower()
you are saying to print the function and then print the string that will take and input, which is in your function so your saying print twice, when you only need to say print the function and since the string that will take and input is in your function it will print it out.