-4

I tell python

Game=input

and then

if Game=="1":
    print("Guess The Number Selected")

and then again

if Game=="2":
    print("Hangman Selected")

But then it ends up printing both!
Also I do

NumberChoice=input

NumberGuess=input

Then I give it

if NumberGuess=="NumberChoice":
    print("Congratulations! You Win.")
else:
    print("Incorrect! Try Again.")

Instead of doing both it ends up doing

Incorrect! Try Again.

It does that twice even when I input the correct number

4

2 回答 2

0

删除两个第一个 if 语句中 1 和 2 周围的引号

同样,改变

`if NumberGuess=="NumberChoice":`

`if NumberGuess == NumberChoice:`

所以你可以比较值

最终代码应该看起来像

Game=input("select a game")
if Game==1:
    print("Guess The Number Selected")

elif Game==2:
    print("Hangman Selected")

NumberChoice=input("choose a number")
NumberGuess=input("guess a number")
if NumberGuess==NumberChoice:
    print("Congratulations! You Win.")
else:
    print("Incorrect! Try Again.")
于 2017-04-27T15:36:22.953 回答
0

应该是:Game=input()
Game=input只是引用函数而不是调用它。

于 2017-04-27T15:38:10.713 回答