forked from mprat/practicepython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,22 @@ | ||
## Exercise | ||
|
||
Given this solution to Exercise 9, modify it to one level of user feedback: if the user does not enter a number between 1 and 9, tell them. Don't count this guess against the user when counting the number of guesses they used. | ||
|
||
``` | ||
import random | ||
number = random.randint(1, 9) | ||
number_of_guesses = 0 | ||
while True: | ||
guess = int(input("Guess a number between 1 and 9: ")) | ||
number_of_guesses += 1 | ||
if guess == number: | ||
break | ||
print(f"You needed {number_of_guesses} to guess the number {number}") | ||
``` | ||
|
||
|
||
## Discussion | ||
|
||
error checking on inputs | ||
can use exercise8 as an example to walk through, since there are a lot of potential error checks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
google.com, pub-6567168629713427, DIRECT, f08c47fec0942fa0 |