I seem to have a problem i dont know how to fix with my program
JJ_graham (4)

It seems to be with the last 3 lines but there's no spelling errors or anything.
Its going to be a guess the number game but i'm stuck with this error. https://repl.it/@JJ_graham/Final-project-Guess-the-number

You are viewing a single comment. View All
heyitsmarcus (287)

Hey @JJ_graham,

You do have several errors here:

  • You've got to make sure that your indentation always stays the same with Python. Be sure that if you're using two spaces for indentation, that you continue to use two spaces for the entirety of the script. Python won't let you indent differently each time you need to indent.
  • The incomplete conditional that @niorg2606 mentioned is also causing the script to error.
  • The _ variable is perfectly valid in Python.
  • On these lines you also have some major errors:
{"number": random.randint(1, 10)  
  ans = input()
if ans1 == "number":

I have to assume you want number to be a variable which is a random integer between 1 and 10. So, you need to set number like so:

number = random.randint(1, 10)

And then for your ans you need to wrap it in an int() method to compare the two or convert the number to a string using the str() method. I would suggest the latter (using str) as it won't break the script if the user inputs something other than a number, like so:

ans = input()
  #and ensure that ans matches the input (there is no ans1)
  if ans == str(number):

I've got the code stored into a repl that you can check out here: https://repl.it/@heyitsmarcus/Final-project-Guess-the-number1

If this solved your problem, please consider upvoting and marking my answer as the accepted answer to close this question. I will continue to answer any questions you might have.