Timeline for Guess the number game using jupyter notebook
Current License: CC BY-SA 3.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 2, 2018 at 19:10 | comment | added | scnerd |
Regarding the __name__ == '__main__' check, see this SO answer or this tutorial. It's not necessary in this case, but again, it's a good habit to get into and is standard practice when writing Python scripts like this.
|
|
| May 2, 2018 at 19:07 | comment | added | scnerd |
To limit the user's input, receive it and parse it to an int, as the current code does, then just add an if statement to check if it's valid: if not 1 <= guess <= 100: print(MESSAGE); continue
|
|
| May 2, 2018 at 19:06 | comment | added | scnerd |
@Ian elif is equivalent to else: if, and should be used when only one of a series of conditions should be entered, exclusive to the others. In your case, the guess is either above, below, or equal to the correct answer, it can never be more than one of those. elif captures this logic cleanly and simplifies your conditions in the process.
|
|
| May 2, 2018 at 19:03 | comment | added | Ian | I applied almost every tip to my code, especially the format strings is a really nice way of cleaning things up but I still had a few questions. In what context does it matter if I use elif instead of if after already using an if conditional? How can I make sure the player can only input a number between 1 and 100? What do you exactly mean with "you should check if name == 'main':", I don't really get what I should achieve with this piece of code and what it does. | |
| May 1, 2018 at 22:10 | history | edited | scnerd | CC BY-SA 3.0 |
Added __name__=='__main__' suggestion
|
| May 1, 2018 at 21:34 | comment | added | Daniel | Yep, that's all. | |
| May 1, 2018 at 21:28 | comment | added | scnerd | @Coal_ Heh, got my markdown code-reviewed :P I've just had issues on SO getting code to format properly between bullets; just double-indenting like that is the solution? | |
| May 1, 2018 at 21:27 | comment | added | Daniel | FYI: you don't need the explicit <!-- language --> declarations. | |
| May 1, 2018 at 21:25 | history | edited | Daniel | CC BY-SA 3.0 |
deleted 90 characters in body
|
| May 1, 2018 at 21:10 | review | First posts | |||
| May 1, 2018 at 21:35 | |||||
| May 1, 2018 at 21:09 | history | answered | scnerd | CC BY-SA 3.0 |