If I'd like to put some input in between a text in python, how can I do it without, after the user has input something and pressed enter, switching to a new line?
E.g.:
print "I have"
h = input()
print "apples and"
h1 = input()
print "pears."
Should be modified as to output to the console in one line saying:
I have h apples and h1 pears.
The fact that it should be on one line has no deeper purpose, it is hypothetical and I'd like it to look that way.
You can do following:
print 'I have %s apples and %s pears.'%(input(),input())
Basically you have one string that you formant with two inputs.
Edit:
To get everything on one line with two inputs is not (easily) achievable, as far as I know. The closest you can get is:
print 'I have',
a=input()
print 'apples and',
p=input()
print 'pears.'
Which will output:
I have 23
apples and 42
pears.
The comma notation prevents the new line after the print statement, but the return after the input is still there though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With