0% found this document useful (0 votes)
39 views

Python Programming

The document summarizes experiments conducted while learning Python programming basics in Chapter 1. It explains that leaving out quotation marks in a print statement or having no operator between values will result in a syntax error. It also discusses that leading zeros are not allowed for decimal integers in Python, but an octal prefix can be used. Additional experiments showed errors from an incorrect print spelling and using an alphabet with a number. Trying the word "slip" prompted Python to ask if the intended function was slice.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Python Programming

The document summarizes experiments conducted while learning Python programming basics in Chapter 1. It explains that leaving out quotation marks in a print statement or having no operator between values will result in a syntax error. It also discusses that leading zeros are not allowed for decimal integers in Python, but an octal prefix can be used. Additional experiments showed errors from an incorrect print spelling and using an alphabet with a number. Trying the word "slip" prompted Python to ask if the intended function was slice.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

PYTHON PROGRAMMING

Learning Journal ( Assignment)

PART 1

. If you are trying to print a string what happens, If you leave out one of the quotation marks why?

Answer

>>> print(God Loves Me)

SyntaxError: invalid syntax.

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.

b. File "<stdin>", line 1

print('God Loves Me)

SyntaxError: unterminated string literal (detected at line 1).

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

File "<stdin>", line 1

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

File "<stdin>", line 1

99

SyntaxError: invalid syntax

-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.

• explain what you learned from the results of each experiment.

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

Downey, A. (2015). Think Python: How to think like a computer scientist.

You might also like