How can use a variable in an input statement and print a comma after a variable with no space?

Posted on 2014-08-16
Last Modified: 2014-08-16
Is there a way to use a variable in an input statement such as miles = int(input(name, 'How many miles to be converted to kilometers?: ')). When I tried this I got TypeError: input expected at most 1 arguments, got 2.
Also, I have print(name,'the conversions for your data are as follows: \n') and I would like to put a comma after name which is a variable without a space. I've tried name, ',' + 'the conversions for your data are as follows: \n', but I get a space between name and the comma.
Question by:Barbara69

    Author Comment

    I got the print to work by doing the following:

    print (name,',', sep='', end=''+ 'the conversions for your data are as follows: \n')

    I forgot to mention, I'm using Python 3.3.2.
    LVL 28

    Accepted Solution

    The input() takes a string used as a prompt. You can prepare the string in advance, or you can concatenate more strings using the + operator, or you can use the .format method of a string used as a template.

    prompt = name + ', how many miles to be converted to kilometers? '
    miles = int(input(prompt))


    miles = int(input(name + ', how many miles to be converted to kilometers? '))


    miles = int(input('{}, how many miles to be converted to kilometers? '.format(name)))

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now