Twelve Years of Service
Posts: 3,251
Threads: 64
Points: 0NSP
RE: [Python] Guess your number 02-09-2013, 04:41 PM
#13
fair enough I'll enter it in then
8
tries:2
•
Twelve Years of Service
Posts: 3,251
Threads: 64
Points: 0NSP
RE: [Python] Guess your number 02-09-2013, 04:41 PM
#14
fair enough I'll enter it in then
8
tries:2
•
Twelve Years of Service
Posts: 3,251
Threads: 64
Points: 0NSP
RE: [Python] Guess your number 02-09-2013, 04:41 PM
#15
fair enough I'll enter it in then
8
tries:2
•
Twelve Years of Service
Posts: 40
Threads: 2
Points: 0NSP
RE: [Python] Guess your number 02-14-2013, 12:24 AM
#16
Code:
low = 0
high = 100
ans = (high + low)/2
print("Please think of a number between 0 and 100!")
while True:
print("Is your secret number "+str(ans)+"?")
x = raw_input("Enter 'h' to indicate the guess istoo high. \
Enter 'l' to indicate the guess is too low. \
Enter 'c' to indicate I guessed correctly. ")
if x == 'h':
high = ans
elif x == 'l':
low = ans
elif x == 'c':
break
else:
print("Sorry, I did not understand your input.")
ans = (high + low)/2
print("Game over. Your secret number was: "+str(ans))
I think this is a good way as well, instead of random I use bisection search, -
in this program I do not count the tries but I can write it in if it's necessary - . I'm a newbie so correct me if I'm wrong, but using this method will get the guessed number faster sometimes.
I wasn't a hacker for the money, and it wasn't to cause damage.
~ Kevin Mitnick
•
Twelve Years of Service
Posts: 40
Threads: 2
Points: 0NSP
RE: [Python] Guess your number 02-14-2013, 12:24 AM
#17
Code:
low = 0
high = 100
ans = (high + low)/2
print("Please think of a number between 0 and 100!")
while True:
print("Is your secret number "+str(ans)+"?")
x = raw_input("Enter 'h' to indicate the guess istoo high. \
Enter 'l' to indicate the guess is too low. \
Enter 'c' to indicate I guessed correctly. ")
if x == 'h':
high = ans
elif x == 'l':
low = ans
elif x == 'c':
break
else:
print("Sorry, I did not understand your input.")
ans = (high + low)/2
print("Game over. Your secret number was: "+str(ans))
I think this is a good way as well, instead of random I use bisection search, -
in this program I do not count the tries but I can write it in if it's necessary - . I'm a newbie so correct me if I'm wrong, but using this method will get the guessed number faster sometimes.
I wasn't a hacker for the money, and it wasn't to cause damage.
~ Kevin Mitnick
•
Twelve Years of Service
Posts: 40
Threads: 2
Points: 0NSP
RE: [Python] Guess your number 02-14-2013, 12:24 AM
#18
Code:
low = 0
high = 100
ans = (high + low)/2
print("Please think of a number between 0 and 100!")
while True:
print("Is your secret number "+str(ans)+"?")
x = raw_input("Enter 'h' to indicate the guess istoo high. \
Enter 'l' to indicate the guess is too low. \
Enter 'c' to indicate I guessed correctly. ")
if x == 'h':
high = ans
elif x == 'l':
low = ans
elif x == 'c':
break
else:
print("Sorry, I did not understand your input.")
ans = (high + low)/2
print("Game over. Your secret number was: "+str(ans))
I think this is a good way as well, instead of random I use bisection search, -
in this program I do not count the tries but I can write it in if it's necessary - . I'm a newbie so correct me if I'm wrong, but using this method will get the guessed number faster sometimes.
I wasn't a hacker for the money, and it wasn't to cause damage.
~ Kevin Mitnick
•