[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

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

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.
0
Barbara69
Asked:
Barbara69
1 Solution
 
Barbara69Author Commented:
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.
0
 
peprCommented:
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))

or

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

or

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now