Being a happy beginner to Python (especially to Python 3.x) Im trying to write number guessing game. Well actually trying to get the game code looking nice to start tinkering with Tk Inter. But when I started cleaning up the code I hit a wall. Interpreter doesnt seem to accept if statement ending with indentation. This is as close to explanation as I can get.
Code:
import random
import sys
import os
i = int
def guessinggame(guess = int(input("Make A Guess: ")), i = 0, randnum = random.randint(1,20)):
while guess != randnum:
guess = int(input("Make A Guess: "))
i = i + 1
if guess == randnum:
OptGame()
elif guess < randnum:
print ("Too low!")
elif guess > randnum:
print ("Too high!")
def optgame(newgame = str(input("Gongrats! \nIt took you only " + str(int(i)) + " tries to guess! \nDo You want to continue? \nType Y for Yes or N for No: "))
if newgame is "Y" or "y":
GuessingGame()
elif newgame == "N" or "n":
quit()
else:
OptGame()
Code looks incoherent because Ive tried just about everything that I could think of and find on google. The Y and N options will later be replaced with buttons but I cant continue before I dont understand why it doesnt work as it is right now. "Thru practice to excellence!" :)
Error:
File "C:/Users/Ajama/PycharmProjects/Test/Tk/GUIGuessingGame.py", line 19
if newgame is "Y" or "y":
^
SyntaxError: invalid syntax
Process finished with exit code 1
ANY help is appreciated. Also remarks/examples about how to better clean up the code is welcome.
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire