Leanring Unit 01 Python
Leanring Unit 01 Python
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 :
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 :
Out put
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.
Answer
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