2 + 2 = 22

In the article Flip a coin
I wrote the following line of Python code.
x= int (input("How Many "))Why not just
X = input (“how many “)Let’s try it and see what happens.
X = input (“how many “)
print (x)It works.
Whatever number you enter is printed to the screen.
The problem is that you did not really print the number 2.
What you printed was the symbol 2.
Print (2) is not the same as print (“2”).
Both of these commands will print what appears to be a number to the screen.
Print (2) will print an integer. That is a simple number without a decimal point.
Prin (“2”) will print the symbol which represents the number 2. This is called a string.
The command input only accepts srings “2 “ or “two” or “#$@!”
If you enter 2 from the keyboard. It can be used as the symbol 2 or the number 2 this is called polymorphism
Let’s see what would happend when we add
X = input (“how many “)
print (x + x)Surprise. You get the answer 22.
Print (“2”+”2”) would return “22”. You can add or join together strings. This is called concatenation.
The function int will convert a string into an integer.
X = int (input (“how many “))
print (x + x)The above code with give you the correct answer which is of course 4.







