python - Python3.2 loops -


# generate random number between 1 , 99 sgenrand.randint(1,99) # code goes here  print("enter coins add 81 cents, 1 per line.")  #promp user start entering coin values add 81   coin = (sgenrand.randint(1,99))  number1 = ("enter first coin: ")  sum = 0    number1 = eval(input("enter first coin: "))  while number1 != coin:        if number1 != coin:      number1 = eval(input("enter next coin: ")) 

im stuck in while loop. want have user can hit enter without answer , breaks out of loop. after breaks out, sum of numbers added calculated, , if sum isn't 81. tells user didn't reach target value, tells him value reached , asks if wants start over!

i doing homework, do:

import random sgenrand  def oneround():     target = sgenrand.randint(1, 99)     print('enter coins add {} cents, 1 per line.'.format(target))     total = int(input('enter first coin: '))     while true:         s = input('enter next coin: ')         if not s: break         total += int(s)     if total == target:         print('well done.')         return true     print('you reached {}.'.format(total))     return input('do want start over? [y/*] ') != 'y'  while not oneround(): pass 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -