[Tutor] Problem in making calulator
kent37 at tds.net
Fri Feb 18 00:32:55 CET 2005
. Sm0kin'_Bull wrote:
> No-one answered question
> So, I e-mail it again
> Help me please
> I wrote this to add 2 numbers...
> print "Please input data"
> number1 = int(raw_input(" "))
> number2 = int(raw_input("+ "))
> total = number1 + number2
> print total
> I want to make output like this...
> 1 + 1 = 2
> But, actually... it looks like this...
This is your input to the first raw_input:
This is the prompt and input to the second raw_input:
> + 1
This is your printed result:
It's not so easy to get the input and output all on one line. What you can do easily is format the
output the way you like. Instead of
print number1, '+', number2, '=', total
That will give you output the way you want it.
You can also do this with the string format operator:
print '%d + %d = %d' % (number1, number2, total)
> Cheers! :)
> Express yourself instantly with MSN Messenger! Download today it's FREE!
> Tutor maillist - Tutor at python.org
More information about the Tutor