Programming Assignment Unit 1
Programming Assignment Unit 1
Part 1
a. If you are trying to print your name, what happens if you leave out one of the quotation
marks or both, and why?
If you leave out one of the quotation marks when trying to print your name, it will result
in a syntax error because in python strings are declared by using both quotation marks of
single or double-quotes.
b. What is the difference between * and ** operators in Python? Explain with the help of an
example.
d. Run the commands type('67') and type(67). What is the difference in the output and why?
In Python, the type() function returns the type of an object. When you execute
these commands- type('67'), type(67) you will get different outputs because the objects
passed to the type() function are themselves different.
These commands will output the type <class 'str'>, showing that the object '67' is a
string type. This is because of the single quotes around the number, indicating a string
literal.
Whereas the type(67) command will output <class 'int'>, as evidence the object 67
is of type integer. Since there are no quotes around the number it is an integer literal.
In Python, string literals are either enclosed in single quotes or double quotes,
while integer literals are numbers without quotes. The type() function returns
appropriately.
Part 2
a. To multiply your age by 2 and display it. For example, if your age is 16, so 16*2 = 32.
To multiply your age by 2 and display the result, you can use the following
formula
b. Display the name of the city country, and continent your are living in.
c. To display the examination schedule (i.e., the starting and the ending day) of this term.
Input:
Output:
d. Display the temperature of your country on the day the assignment is attempted by you
References
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree
Press. https://greenteapress.com/thinkpython2/thinkpython2.pdf