1
+ '''Author: - Devang A Joshi
2
+ Version 1.0
3
+ Description: This program is a mini guessing game where User need to think a value between 1 to 100
4
+ an Array of 100 is created, Initial vales were set. then sorting is made by midpoint selection
5
+ Guided By : - Gula Nurmatova
6
+ '''
7
+
8
+
9
+ print ("----------------------------------------" )
10
+ print ("----| | |--- | | ---- --------" )
11
+ print ("----|--| |__ | | | | --------" )
12
+ print ("----| | |___ |___ |___ |____| --------" )
13
+ print ("----------------------------------------" )
14
+
15
+ name = input ("PLEASE ENTER YOUR NAME \n " ) #Getting the name of the User
16
+ print ( "\t " + name + " well come to Guessing number game\n " ) #Printing the name of the User
17
+
18
+ print ("\t Guess any Number between 1 to 100\n " )
19
+
20
+ a = [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 , #Defining an array of 100 values from 1 to 100
21
+ 26 ,27 ,28 ,29 ,30 ,31 ,32 ,33 ,34 ,35 ,36 ,37 ,38 ,39 ,40 ,41 ,42 ,43 ,44 ,45 ,46 ,47 ,
22
+ 48 ,49 ,50 ,51 ,52 ,53 ,54 ,55 ,56 ,57 ,58 ,59 ,60 ,61 ,62 ,63 ,64 ,65 ,66 ,67 ,68 ,69 ,
23
+ 70 ,71 ,72 ,73 ,74 ,75 ,76 ,77 ,78 ,79 ,80 ,81 ,82 ,83 ,84 ,85 ,86 ,87 ,88 ,89 ,90 ,91 ,
24
+ 92 ,93 ,94 ,95 ,96 ,97 ,98 ,99 ,100 ]
25
+ play = "yes" #let the initial state of the game be yes.
26
+ while (play == "yes" ):
27
+ Vmid = (a [99 ]+ a [0 ])// 2 #Getting the first MID value from the array which is 50
28
+ Vmax = a [99 ] #Defining the Max value in array
29
+ Vmin = a [0 ] #Defining the Min value in array
30
+ tries = 0 #Initial number of tries be 0
31
+
32
+ guess = input ("\t Is the number " + str (Vmid ) + " ? (yes/no) \n Ans." ) #Guessing the Number and getting input from user is it correct or not
33
+ tries = tries + 1 #Incrementing the tries by 1
34
+ if (guess == 'yes' ): #If the input value from the user is "yes" then following lines will be executed
35
+ print ("\t PERFECT I am Genius" )
36
+ print ("\t I got your number in " + str (tries ) + " try" )
37
+ else : #Else the input value from the user is "no" then following lines will be executed
38
+ Nguess = input ("\t Is the number Greater than " + str (Vmid ) + " (Yes/No)?\n Ans." )
39
+
40
+ while (guess == 'no' and (Nguess == 'yes' or Nguess == 'no' )): #While loop will run till the value of guess is no and either value of Nguess
41
+ while (Nguess == "yes" ): #While the value of Nguess is "yes" following will be executed
42
+ Vmin = Vmid + 1 #Changing the Min value by adding 1 to the Mid value
43
+ Vmid = ((Vmax + Vmin )// 2 ) #Recalculating the Mid value
44
+ guess = input ("\t Is the number " + str (Vmid ) + "? (Yes/No)\n Ans." )
45
+ if (guess == 'no' ):
46
+ tries = tries + 1
47
+ Nguess = input ("\t Is the number Greater than " + str (Vmid ) + "?(Yes/No)\n Ans." )
48
+ elif (guess == 'yes' ):
49
+ tries = tries + 1
50
+ print ("\t I guessed it in " + str (tries ) + " tries." )
51
+ break
52
+
53
+ while (Nguess == "no" ): #While the value of Nguess is "no" following will be executed
54
+ Vmax = Vmid - 1 #Changing the Max value by subtracting 1 to the Mid value
55
+ Vmid = ((Vmax + Vmin )// 2 ) #Recalculating the Mid value
56
+ guess = input ("\t Is the number " + str (Vmid ) + "? (Yes/No) \n Ans." )
57
+ if (guess == 'no' ):
58
+ tries = tries + 1
59
+ Nguess = input ("\t Is the number Greater than " + str (Vmid ) + "?(Yes/No)\n Ans." )
60
+ elif (guess == 'yes' ):
61
+ tries = tries + 1
62
+ print ("\t I guessed it in " + str (tries ) + " tries." )
63
+ break
64
+ play = input ("Lets Play again !!!!! (yes/no)" ) #taking input from the user to play again
0 commit comments