python - How to make 'seat' in user input returned as a float -
so in short python program, wrote:
print "welcome receipt program!" while true: seat = raw_input('enter value seat: ["q quit"] ') if seat not seat.isdigit(): print "i'm sorry {} isn't valid. please try again.".format(seat) if seat == 'q': break else: continue print "*****" total = seat.count('$') print total
how set so, whenever user enters number (a float specifically) seat (currently not possible in snippet), continues code , adds user inputs? beginner apologies if it's obvious answer.
print "welcome receipt program!" seats = [] while true: seat = raw_input('enter value seat: ["q quit"] ') if seat == 'q': break try: seats.append(float(seat)) except valueerror: print "i'm sorry {} isn't valid. please try again.".format(seat) print "*****" print '$', sum(seats)
note order in check values of input important (checking 'q'
first before trying convert float)
Comments
Post a Comment