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 | import random low = 0; high = 100; ans = 0; print("Haay.. I'm Hyosoka's awesome guess number"); print("So...Please Choose number between 0 and 100....Then I'm gonna guess your secret number... :D"); print("Done...? y or n"); usr=raw_input(); while(usr == "n"): print("Please Choose number between 0 and 100...."); print("Done...? y or n"); usr=raw_input(); ans = random.randint(0,100); print("Is your secret number = " + str(ans)); print(""); guess = raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly"); while (guess != "c"): if( guess == "h"): high=ans; ans = (low+high)/2; elif(guess == "l"): low = ans; "high = 100;" ans = (low+high)/2; else: while((guess != "h") or (guess != "l")): print("Sorry... I don't understand your input"); guess = raw_input("Please just enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low "); if(guess == "h" or guess == "l"): break; print("Is your secret number = " + str(ans)); guess = raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly"); print("Yeeei... So your secret number is = "+str(ans) +" heheh... :D"); |
Yang itu udah ditest... dan berhasil... nah pas dimasukin ke edx-nya diubah jadi kyk gini :
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 | low = 0; high = 100; ans = 0; print "Please think of a number between 0 and 100!" ans = 50; print("Is your secret number = " + str(ans)); print(""); guess = raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly"); while (guess != "c"): if( guess == "h"): high=ans; ans = (low+high)/2; elif(guess == "l"): low = ans; "high = 100;" ans = (low+high)/2; else: while(guess != "c" or guess != "h" or guess != "l"): print("Sorry... I don't understand your input"); guess = raw_input("Please just enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly"); if(guess =="h" or guess =="l"): break; print("Is your secret number = " + str(ans)); guess = raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly"); print("Game over. Your secret number was: "+str(ans)); |
Cuman dianggap salaah.... :v seharusnya udah bener, soalnya udah ditest di canopy... :v
Mmmm.... tapi udah ngelapor... ehehe... :D
Btw... jawaban dari edx-nya seperti ini :
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 | print("Please think of a number between 0 and 100!") # At the start the highest the number could be is 100 and the lowest is 0. hi = 100 lo = 0 guessed = False # Loop until we guess it correctly while not guessed: # Bisection search: guess the midpoint between our current high and low guesses guess = (hi + lo)/2 print("Is your secret number " + str(guess)+ "?") user_inp = raw_input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly. ") if user_inp == 'c': # We got it right! guessed = True elif user_inp == 'h': # Guess was too high. So make the current guess the highest possible guess. hi = guess elif user_inp == 'l': # Guess was too low. So make the current guess the lowest possible guess. lo = guess else: print("Sorry, I did not understand your input.") print('Game over. Your secret number was: ' + str(guess)) |
Sekian dulu... :)
No comments:
Post a Comment