File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change
1
+ #Letting the computer guess your Number
2
+
3
+ import random
4
+
5
+ def computer_guess (x ):
6
+ low = 1
7
+ high = x
8
+ feedback = ''
9
+ while feedback != 'c' :
10
+ if low != high :
11
+ guess = random .randint (low , high )
12
+ else :
13
+ guess = low # it can be low or high since low == high.
14
+ print ("Please enter (h) If the number guessed by the computer is Higher than your number, (l) If it's Lower and (c) If it's the Correct number.\n " )
15
+ feedback = input (f"Is { guess } , High(h), Low(l), or Correct(c)??\n " )
16
+ if feedback == 'h' :
17
+ high = guess - 1
18
+ elif feedback == 'l' :
19
+ low = guess + 1
20
+
21
+ print (f"Yeahh! Finally the computer guessed your number, { guess } , correctly!" )
22
+
23
+ computer_guess (1000 ) #You can update the value, it's upto you :)
You can’t perform that action at this time.
0 commit comments