[Tutor] Problem in making calulator

Kent Johnson 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
> 
> raw_input("")
> 
> 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:
> 1

This is the prompt and input to the second raw_input:
> + 1

This is your printed result:
> 2

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 total

try
   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)

Kent

> 
> 
> Cheers! :)
> 
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today it's FREE! 
> http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 




More information about the Tutor mailing list