6

Coming to the end of beginners python and added a new loop to a number guessing game and now my elif is invalid syntax.

Comments
  • 1
    Sorry but just from the image it looks like the error could be due to the fact you're trying to convert a string with no numerical values in it into an int, then again maybe you've just deleted something there, but that's what I looks like from here
  • 0
    Just to clarify, I mean the thank you string
  • 1
    @hidden sorry it actually says print not int, but that is later in the code anyway, I'm just so annoyed I had it working fine as a single game, wanted to add an option to play again and the whole game breaks.
  • 0
  • 1
    Well then that's not the issue, just out of curiosity how are you trying to do it? Did you try making the game a function that's called by an option in a menu that acts as a restart point? (I think that makes sense, my brain is melted tonight after a chemistry A-level paper the day so I apologise if I sort of ramble)
  • 1
    @hidden nope, I have while loop with the condition that newGame = 'yes' and then the game is a while loop nested in the first while loop. The only think I did is create a new while loop and move the original into the new one.
  • 2
    Oh thanks, just seen the screenshot, oh and you don't need to use the int() function, python auto evaluates the input and detects that it's an int when you use input(), you only need int() for the input if you use raw_input()
  • 0
    @hidden oh on the tutorial I was following it said to use the int() currently trying to make the code work first though haha
  • 8
    The "guess" needs to be indented.
  • 2
    @jirehstudios wow! I can't believe it was as simple as that! Thanks! :D
  • 2
    Aye ^ your man above is right, every line in an IF or ELIF or ELSE statement needs to be indented the same amount so check that and try again☺️
  • 1
    @hidden I did it and it fixed it! I was being so dumb but it fixed it!
  • 3
    Oh and by the way since it seems you're just learning it, I would suggest you give codecademy.com a 👀 up, I found them to be pretty helpful when I started off, plus they have a support board thing that directly relates to their tasks so you can get help with any issue on the courses, only downside is their Java course for some reason has a very bad habit of freezing and some of the more complex languages aren't anywhere as near well layed out as the 🐍 course
  • 3
    Oh for fucks sake, iOS 10 would appear to be a bit over zealous with the changing words to emojis features
  • 1
    @hidden yea I've used them before but when I was doing python I was just not motivated by doing it on codeacademy, but with the course I've just done it's taken me a week for the basics and have an advanced course that I'll do soon just gonna get used to the beginners stuff first. Thanks for the help though man.
  • 3
    Well whatever works for you lad, as long as you enjoy it and make something deadly with it👊
  • 1
    @SoldierPeetaM Python relies on indentation to read code, that's why it has no braces or semicolons. It was thinking that "guess" was outside the if statement.
  • 0
    u nid more practice
  • 0
    @hidden hey tried taking out the int() it said unorderable types: str() < int() so I do need the int() thanks for trying to help though dude
Add Comment