Python Programming
Python Programming
PART 1
. If you are trying to print a string what happens, If you leave out one of the quotation marks why?
Answer
Which indicates that, If I have a sentence without quotations and spaces in between them , it
appears a” SyntaxError: invalid syntax” as shown above, indicating that, there is an error in the
arrangement of the sentence.
Which indicates that, If I omit a quotation mark in the sentence ,the results will be displayed as
shown above, which indicates its impossibility to determine the beginning and the end of the
sentence.
2. You can use a minus sign to make a negative number like -2. What happens for each of the
following and why?
>>> 2++2
>>> 2--2
>>> 2+-2
>>> 2-+2
Answer
These are mathematical calculations which the python program also does, which indicate that, it
acts as a calculator in mathematics problem solving with the help of the operation signs; plus (+),
minus (-), multiply(*) and divide (/).
Now, Lets move to the questions above and solve them with the instruction indicated;
• >>> 2++2
-The answer to this statement is 4, indicating the addition of two positive numbers.
b. >>> 2—2
-The answer to this statement is 4, indicating the changing of equation into addition when the
subtraction sign is infront of -2.
c. >>> 2+-2
-The answer to this statement is 0, illustrating that, adding of a positive number to a negative
number is shown to be subtraction of such statement.
d. >>> 2-+2
-The answer also to this statement is 0, indicating that , the first operation sign is minus sign,
which states that ,the statement will undergo a subtraction method.
3. In math notation, leading zeros are OK, as in 02. What happens if you try this in Python? Why?
Answer
>>> 02
02
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal
integers.
-indicating that, python 3 does not permit leading zeros which generates error as shown in the
display above.
4. What happens if you have two values with no operator and a space between them? Why?
>>> 9 9
99
-That is, If I have two digits or values without an operator and space in between them, the
python will display it as shown above.
PART 2
Describe at least three additional Python experiments you tried while learning Python language
in Chapter 1. In the same Word document used in Part 1, add the following:
• include Python code and screenshots of your output.
Answer
1.
-There was an error in the word print which cause the statement not to display because, the
interpreter cannot define the operator.
2.
-This indicates that, the python could not read the number attached with an alphabet, Thus
giving an error as displayed above. Python thought it would be a normal decimal number.
3.
-To explore more out of curiosity, I tried the word “slip”which resulted in python asking me ,if it
was slice I was inputting , which indicates that, there are some specific words or values that
Python can read followed directly by the prompt, not only ‘’print”.
References