Guessinggame (replace variable issue)
<p>so doing this for my stage 1 computer science paper. following code is what i've written atm. Line 16 (while statement) is giving a syntax error. The book asks us to</p>

<p>1) prompt the user to enter a guess and store the value in the "guess" variable,<br>
2) if guess is greater than goal print...<br>
3) if guess is lower than goal... print...<br>
4) if guess is same as goal, print...  </p>

<p>Unsure how to fix this. Any help will be greatly appreciated. Code as below.</p>

<pre><code>#Author: Anuj Saluja
#Date: 17 October 2016
import random

goal = random.randint(1,100)

guess = 0

print ("The object of this game is to")
print ("guess a number between 1 and 100")
print()

inputguess = int(input("Please guess the number: ")

while (guess != goal):
                 if inputguess &gt; goal
                 print ("Too high, try again.")
                 if inputguess &lt; goal
                 print ("Too low, try again.")
                 if inputguess == goal:
                 break
if inputguess == goal:
                 print ("Well done!")
                 print ("See you later.")
</code></pre>

<p>Have you read your stack trace in detail? It's very easy to just skim over them, but stack traces can actually provide a lot of very useful information. For instance, the message is probably complaining that it was expecting a closing parenthesis. The line:</p>

<pre><code>inputguess = int(input("Please guess the number: ")
</code></pre>

<p>should actually be</p>

<pre><code>inputguess = int(input("Please guess the number: "))
</code></pre>

<p>The stack trace says the error is on line 16 because that's where the interpreter realized something was wrong. More often than not, the buggy code will be in the last line of code before the line it gives you.</p>

<p>also as other people stated, you need to put the input statement within the while loop in order to update the variable.</p>

<p>You should also consider replacing tab characters with 4 spaces so it displays consistently no matter where you read it. Usually the text editor or IDE will have tab settings that you can change when you hit tab, it will type 4 spaces. A quick Google search along the lines of "{text editor} change tab settings" will usually bring up results on how to change it, where {text editor} is the name of the editor/IDE you're using.</p>

<p>You should also consider indenting the code within your if statements as it improves readability</p>

python python-3.x