Programming Assignment Unit 1 (2)
Programming Assignment Unit 1 (2)
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 I run this code as shown as above, I get a Syntax Error because the string is not properly
terminated.
If I run this code as shown as above, I get a Syntax Error because Python expects a string,
and “Khaing Khant Kyaw” without quotes is treated as a variable, which is not defined.
b. What is the difference between *and** operators in Python? Explain with the help of an
example.
In the example below, the * operator is used for multiplication, and output will be 15.
In the example below, the ** operator is used for exponentiation, and the output will be 8.
c. In Python, is it possible to display an integer like 09? Justify your answer.
According to the above, it is not possible to display an integer like 09 in Python. When I
run this code, I get a SyntaxError because integers with leading zeros are treated as octal literals,
and 09 is not a valid octal number.
d. Run the commands ‘type(‘67’) and ‘type(67)’. What is the difference in the output and
why?
The output will be ‘<class ‘str’>’ according to above because ’67’ is a string.
a. To multiply your age by 2 and display it. For example, if your age is 16, so 16 * 2 = 32 b.
Explanation: This code takes user input for age of 22, converts it to an integer, multiplies
it by 2, and then prints the result. As a result, I got 44.
b. Display the name of the city, country, and continent you are living in.
Explanation: This code takes user input for city, country, and continent, and then prints
the information in a formatted string.
c. To display the examination schedule (i.e., the starting and the ending day) of this term.
Explanation: This code takes user input for the starting and ending days of the
examination.
d. Display the temperature of your country on the day the assignment is attempted by you.
Explanation: This code takes user input for the temperature of country and print it in a
formatted string.
You should ensure that whenever you run these codes in a Python environment for your
programming assignment, provide screenshots of the outputs as needed in your Word
document. Additionally, in the descriptive part, you can discuss any challenges faced,
improvement that can be made, or any interesting observation from running these
programs in Python environment.
Word Count – 344 words (excluding questions and cover page)
References
Allen Downey, J. E. (2015). How to Think Like a Computer Scientist. In A. Downey, Think Python (p. 1 to
6). 9 Washburn Ave, Needham MA 02492: Green Tea Press.