[Tutor] stuck on null values

Joel Goldstick joel.goldstick at gmail.com
Thu Mar 15 22:38:52 CET 2012


On Thu, Mar 15, 2012 at 5:24 PM, ADRIAN KELLY <kellyadrian at hotmail.com> wrote:
> Please can anyone tell me how to solve the problem i am having here, i am
> trying to loop if the value is left blank by the user
> but how can i then use the value and multiply it.  e.g. while
> number_child==""............ i want to multiply the input i get.........???
>
> def main():
>     print """
> ________________________________________________________
>
>                 Welcome to the Travel Kiosk
> ________________________________________________________
> """
>
>     adult=15
>     child=5
>     firstname=raw_input("Please enter your firstname: ")
>     lastname=raw_input ("Please enter your lastname: ")
>     number_child=raw_input("Enter the number of kids: ")
>     number_adults=raw_input("Enter the number of adults: ")
>     while number_child=="":
>         number_child=raw_input("Enter the number of kids: ")
>     price=child*number_child
>
>
>     print """
> _______________________________________________________
>
> Thank you, the Price will be: """,price
>     print"""
> _______________________________________________________
> """
>
> main()
>
>
>
>
>
>
> Adrian Kelly
> 1 Bramble Close
> Baylough
> Athlone
> County Westmeath
>
> 0879495663
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
raw_input returns the values the user types as a string.  In python if
you have 3 * 'bob' the result will be "bobbobbob"

So you need to turn the number_child into a number like so:  int(number_child)

You will need to do the same thing for the number of adults.

That will get you started, but if your user types in something that
isn't a number, your program will fail.  See if you can get it to work
for good data and then come back with what happens when you type in
other than integers.

Also, when your program fails, it prints out what is called a
traceback.  When you get this situation, be sure to post the traceback
with your problem.  It helps figure out what went wrong


-- 
Joel Goldstick


More information about the Tutor mailing list