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

Programming Assignment Unit 1 (2)

The document is a programming assignment for CS-1101-01 at the University of the People, authored by Zin Myo Tun. It includes explanations of Python syntax errors, operator differences, and data types, along with programming tasks such as multiplying age and displaying personal information. The assignment emphasizes the importance of providing screenshots of outputs and discussing challenges faced during coding.

Uploaded by

Zin Myo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Programming Assignment Unit 1 (2)

The document is a programming assignment for CS-1101-01 at the University of the People, authored by Zin Myo Tun. It includes explanations of Python syntax errors, operator differences, and data types, along with programming tasks such as multiplying age and displaying personal information. The assignment emphasizes the importance of providing screenshots of outputs and discussing challenges faced during coding.

Uploaded by

Zin Myo
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Programming Assignment Unit 1

Zin Myo Tun


Department of Computer Science, University of the People
CS-1101-01: Programming Fundamentals - AY2024-T2

Mr. Vikas Thada


Instructor, Department of Computer Science
University of the People
November 23, 2023
Part 1: LEARN FROM YOUR MISTAKES!

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?

When run ‘type(‘67’),

The output will be ‘<class ‘str’>’ according to above because ’67’ is a string.

When run ‘type(67)’,

The output will be ‘<class ‘int’>’ because 67 is an integer.


In summary, the ‘type( )’ function is used to determine the data type of a variable. In the
first case, ‘67’ is a string, and in the second case, 67 is an integer.
Part 2: Write a Python program for each of the following questions (a) to (d).

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)

(Allen Downey, 2015)

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.

You might also like