-
Notifications
You must be signed in to change notification settings - Fork 0
/
guess4.exem
81 lines (77 loc) · 1.53 KB
/
guess4.exem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""
guess4. Adapted from http://inventwithpython.com/invent4thed/chapter3.html 2/1/2019
This shows how user interaction and program calls can be modelled.
"""
# User wins.
>Hello! What is your name?
<Albert
name
>secret = random.randint(1,20) # This just gets printed currently.
<4
secret # This & above line become: secret = int(input("secret:")) # Eg, 4
>Well, Albert, I am thinking of a number between 1 and 20.
guess_count==0 # iteration
>Take a guess.
<10
guess
guess>secret
>Your guess is too high.
guess_count == 1 # iteration
>Take a guess.
<2
guess
guess<secret
>Your guess is too low.
guess_count==2 # iteration
>Take a guess.
<4
guess
guess==secret
guess_count + 1 == 3 # The 3 here needed for below 3 to get swapped for a variable.
>Good job, Albert! You guessed my number in 3 guesses!
# User loses.
>Hello! What is your name?
<John
name
>secret = random.randint(1,20)
<3
secret
>Well, John, I am thinking of a number between 1 and 20.
guess_count==0
>Take a guess.
<11
guess
guess>secret
>Your guess is too high.
guess_count == 1
>Take a guess.
<1
guess
guess<secret
>Your guess is too low.
guess_count==2
>Take a guess.
<2
guess
guess<secret
>Your guess is too low.
guess_count==3
>Take a guess.
<10
guess
guess>secret
>Your guess is too high.
guess_count==4
>Take a guess.
<9
guess
guess>secret
>Your guess is too high.
guess_count==5
>Take a guess.
<8
guess
guess>secret
>Your guess is too high.
guess_count >= 5 # User avoids guess_count == 5, as that'd look like another iteration.
>Nope. The number I was thinking of was 3.