[Tutor] Advanced Calculator Program...
Gregor Lingl
glingl at aon.at
Sun Feb 20 00:12:13 CET 2005
. Sm0kin'_Bull schrieb:
> I want to make caculator program which enables me to
> enter 2numbers and mathsmatics sign and calculates it.
> I think this is too difficult for newbie like me...
>
> Please input data
>
> Number1:
> Mathsmetics Sign:
> Number2:
>
> (Number1) (Sign) (Number2) = (Result)
>
>
> I wrote this but, Error occurs
>
> print "Please input data"
> number1 = int(raw_input("\nNumber1: "))
> sign = (raw_input("\nMathsmetics Sign: "))
> number2 = int(raw_input("\nNumber2: "))
>
> total = number1 sign number2
> print number1, sign, number2, '=', total
>
hey, bull! that's a bit tricky. You had a nice
idea, but it doesn't work in Python. The point is,
that you must not use names for operators in
arithmetic expressions. Those operators have
to be used literally.
*One* way to solve your problem is, e. g., to
use a branching statement for checking, which
operator is used.
So replace the line
total = number1 sign number2
by something similar to
if sign == "+":
total = number1 + number2
elif sign == "-":
total = numer1 - number2
... (for other operators ..)
HTH,
Gregor
> please help me
>
>
>
> 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
>
>
--
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien
Telefon: +43 1 713 33 98
Mobil: +43 664 140 35 27
Autor von "Python für Kids"
Website: python4kids.net
More information about the Tutor
mailing list