Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2003
    Location
    California
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy python input problem

    this code is being difficult with me. It says that the " mark by the word "are" is wrong..but i dont know why. I tried to seperate the " marks and commas but that didn't seem to help much.


    print "Welcome to my program "
    print "Please type your name, age, city, state, and zip,"

    name = input("name ")
    age = input("age ")
    city = input("city ")
    state = input("state ")
    zip = input("zip ")

    print "Your name is", name "you are", age "years old and live in", city , state, zip
    print "Thank you for joining us!."

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    print "Welcome to my program "
    print "Please type your name, age, city, state, and zip,"

    name input("name ")
    age input("age ")
    city input("city ")
    state input("state ")
    zip input("zip ")

    print 
    "Your name is"name "you are"age "years old and live in"city statezip
    print "Thank you for joining us!." 
    try adding the line
    PHP Code:
    print "Your name is %s your age is %s years old and live in %s %s %s" % (nameagecitystatezip
    other wise to use your print statment, don't use the double quotes, use single quotes and it should work.


    Jason

  • #3
    Regular Coder
    Join Date
    Jun 2003
    Location
    California
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs down

    Jason, it did not work, but thats ok..i'll keep working at it.. was wondering what does the %s mean?

  • #4
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    %s basically says you are using a string variable....so if you were using an int it would be %i and double/floats are %f extended florats are %ef or something...but then at the end you say what variables go in the order in which you use the variables...

    print "%s %i %s %s %i " % (name, age, city, state, zip)

    where name = string
    age = int
    city = string
    state = string
    zip = int

    and they correspond to the porper var call, maybe try taking the '%' out that seperates the vars and the printing string.....


    Jason


  •  

    LinkBacks (?)

    1. 06-20-2014, 11:20 AM

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •