Python adding whitespace prior to print statement -
my python code:
guess = 50 high = 99 low =0 hilo = 0 print ('please think of number between 0 , 100!') while hilo != 'c': print ('is secret number ' + str(guess) + ' ?') print ("enter 'h' indicate guess high. enter 'l' indicate guess low."), hilo = raw_input ("enter 'c' indicate guessed correctly. ") if (hilo != 'c' , hilo != 'h' , hilo != 'l'): print 'sorry, did not understand input.' if hilo == 'l': low = guess guess = (high + low) / 2 if hilo == 'h': high = guess guess = (high + low) / 2 print ('game over. secret number was: ' + str(guess))
prints this:
please think of number between 0 , 100! secret number 50 ? enter 'h' indicate guess high. enter 'l' indicate guess low. enter 'c' indicate guessed correctly. h secret number 25 ? enter 'h' indicate guess high. enter 'l' indicate guess low. enter 'c' indicate guessed correctly. l secret number 37 ? enter 'h' indicate guess high. enter 'l' indicate guess low. enter 'c' indicate guessed correctly.
the first execution of following line of code aligned rest of output subsequent executions have single space in front.
print ('is secret number ' + str(guess) + ' ?')
what causing that?
run instead, have comma @ end of line (at third print statement):
guess = 50 high = 99 low =0 hilo = 0 print ('please think of number between 0 , 100!') while hilo != 'c': print ('is secret number ' + str(guess) + ' ?') print ("enter 'h' indicate guess high. enter 'l' indicate guess low.") hilo = raw_input ("enter 'c' indicate guessed correctly. ") if (hilo != 'c' , hilo != 'h' , hilo != 'l'): print 'sorry, did not understand input.' if hilo == 'l': low = guess guess = (high + low) / 2 if hilo == 'h': high = guess guess = (high + low) / 2 print ('game over. secret number was: ' + str(guess))
Comments
Post a Comment