Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

PART 1

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

It will give a syntax error, as the quotation marks the beginning and ending
of the statement

You can use a minus sign to make a negative number like -2. What
happens for each of the following and why?

It is a a valid token, hence python can be use as a calculator

>>> 2++2
4
>>> 2--2
4
>>> 2+-2
0
>>> 2-+2
0

In math notation, leading zeros are OK, as in 02. What happens if you
try this in Python and why?

It is an invalid token, numbers in python with leading zeros will give a


syntax error.

What happens if you have two values with no operator and a space in
between them and why?

It will give a syntax error as this statement is not a valid.

PART 2
Next, describe at least three additional Python experiments that you
tried while learning Chapter 1. Show the Python inputs and their
outputs, and explain what you learned from the results of each
example. 

Doing the exercise in chapter 1 help in practicing using the operators and
its rule.

>>> (42*60) + 42
2562

>>> 10/1.61
6.211180124223602

>>> 2562/(60*60)
0.7116666666666667

>>> 6.211180124223602/0.7116666666666667
8.727653570337614
>>>

Experimenting with the print function, I wrote it in different ways to see the
result

>>> print("my name is wendy")


my name is wendy

>>> print("my name is wendy)


SyntaxError: EOL while scanning string literal

>>> print"my name is wendy"


SyntaxError: invalid syntax

>>> print(my name is wendy)


SyntaxError: invalid syntax
And using the type function I learned the difference between “string” , 45
integer, 45.4 float.

>>> type(45.4)
<class 'float'>

>>> type("hello world")


<class 'str'>

>>> type(45)
<class 'int'>

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

You might also like