0
any one have a problem to run the calc..
please help
4 Answers
+ 3
[ THE NEXT -- because of limited post size ]
But there come expression literals: like you assign a string or a numeric litteral to a variable, you can assign it a "complex" expression, wich combine values literals and operators ( in fact, operators or functions are pretty equivalent, in the measure that they takes values and return a result ). So what? You can write directly:
print(2+3)
... because in between parenthesis, Python find an expression literal, composed by two numerics and an operator.
However, you'll say: what for the function int() then? Well, essentially in case of you get input from the user, which comes as string... ( and all the time you've a stored value wich you want convert the type ).
Ok, before continuing, can you explain now the differences between this two instructions:
print(2+3)
print("2+3")
?
If you do, you can now too understand your mistake at the last line of your code ;)
Else, I would try to complete/continue my explanation :P
+ 2
If you're talking about this code ( the only public one in your code playground ):
print ("hi bebe")
e = 2
print(int("2") + int("3"))
print (e)
x = 5
print ("x+e=7")
You have to distinguish strings literals versus expressions literals ^^
In first list, you pass to the function print ( in the parenthesis ) a string literal: you've put the sentence ( string ) in between quotes which are delimiters to tell to Python "Hey! from now and until the next quotes, this is text data I want to use". So, you can use it directly ( like by passing it to the print function ), or store it in a variable:
my_sentence = "hi bebe"
It's also what you do in second line: you ask to Python to store the value 2 in the variable named "e" ( this and my previous example are called "assignation": you assign a value to a variable ). Well, this two is also a literal, but numeric, so you don't enclose it with quotes. And Python, automaticaly will remember that the variable "e" contain an integer, and the variable "my_sentence" a string ( the type of the stored value ).
In reality, Python convert the characters form number you've entered in the text file of your script, but silently, automaticaly...
On line three, begin the big mistake...
Even if this instruction is correct in sense of Python execute it without error and you get the expected result, you become confused. To begin, look at only the in between parenthesis of your print function ( which his result will be passed/assigned to the parameter of the function ):
int("2")+int("3")
Do you start to see what I attempt to make you understand? You call twice the function int ( which take a parameter to be converted in a integer value ), addition the two returned values ( and so, print this last result ). What are your "2" and your "3"? Two strings literal, because they are enclosed by quotes ^^, so when the int function has returned the two result, for Python, the next step is to calculate the addition ( 2+3 ).
[ TO BE CONTINUED... ]
+ 2
I used to but now no
0
thank you visph this was a drift code for fun
im asked to try making a calculator app at python 2.7.1
that were the input func replaced by raw_input
and that my mistake