Why is the output of print("COMPUTER:"guess) not appearing on the console?

914 views python
1

I am writing a program in python where you have to guess the number chosen by the computer. The number will be chosen between 0 and 10(inclusive of both the number). If the number guessed by the user is correct or wrong, a message will be shown based on the validity of the input (the number guessed by the user), followed by the number chosen by the computer as the outputs. The output should be something like this.

ENTER: 4
Wrong
Computer: 10

OR

ENTER: 10
RIGHT!
Computer: 10

The Problem is that the computer's choice(Computer:10) is not appearing on the console window. The IDE on which I am making this program is telling me that "CODE IS UNREACHABLE".

My code: IDE = Pycharm

from random import randint
def guessing_game(x):
    guess = randint(0,10)
    if x.isdigit():
      if x==guess:
          return "RIGHT!"
          print(" COMPUTER =" guess)
      else:
          return "Wrong"
          print("COMPUTER="guess)
    elif x.isdigit() == False:
          return " Enter a Number"

print(guessing_game(input("ENTER:")))


Therefore, please help me to solve this issue.All suggestions will be appreciated.

Thank You

answered question

1 Answer

7

Your print is placed after a return instruction. That means at the execution in the case the user as found the guessed number, your function will return "RIGHT!" and stop execution of further code within this function.

posted this

Have an answer?

JD

Please login first before posting an answer.