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

Leanring Unit 01 Python

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Leanring Unit 01 Python

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

LEARN JOURNAL OF UNIT 1 PYTHON UOPEOPLE

LEANRING FROM YOUR MISTAKES!


In Chapter 1, section 1.9 Exercises (pg. 7) of your textbook, Exercise 1.1

Question a

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

Answer :

My name is Thierry Murhondezi Bisimwa

So I tried to write a program that displays my name on the screen, but left l the LAST
quotation marks of a string away ,

See screenshot

Input :

‘Thierry Murhondezi Bisimwa

Out put

File "<stdin>", line 1


print ('Thierry Murhondezi Bisimwa)
^
SyntaxError: unterminated string literal (detected at line 1)

Explanation
In fact this is a syntax error; the “quotation marks” indicates the beginning and the end of a
string text …. So by missing away on of both the quotations marks , the computer program
doesn’t know where your string starts or where it ends , in our case , it’s the end of the
string that is not defined into our syntax
Question b

b. What is the difference between * and ** operators in Python? Explain with the help
of an example.

* operator : stands for multiplication


For example
>>>2*3
6

See the shot

** Operator : stands for exponentiation


For example
>>>2**3
8

See the screen shot


Question C

c. In Python, is it possible to display an integer like 09? Justify your answer.

Answer

No , it is not possible to display integer 09 , because Python interprets it as a sequence with


a significant integer that is 9
Python says :

Input
>>> type(09)

Output
File "<stdin>", line 1
type(09)
^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for
octal integers

See screen

Question D

d. Run the commands type('67') and type(67). What is the difference in the output
and why?

Answer

>>> type('69')
<class 'str'>
>>> type(67)
<class 'int'>
>>>
The difference is that having put ‘69’ into quotation marks , indicates it as an integer to
string to python , not as an integer , while type(69) , gives us the output indicating that 69 is
a regular integer

Screen

Part 2:

Question A

a. To multiply your age by 2 and display it. For example, if your age is 16, so 16 * 2 =
32

>>>32*2
64
Screen
Question B

b. To Display the name of the city, country and continent you are living in.

answer

>>>print(‘Kentucky’)
Kentucky

screen

You might also like