CS 1101 – Programming Fundamentals
University of the People
Programming Assignment Unit 1
Part 1:
(a) Printing Name with Missing Quotation Marks
When I attempt to print a string in Python without enclosing it in quotation marks, Python does
not recognize the text as a string. Instead, it treats it as a variable name or an expression, leading
to a SyntaxError if such a variable is not defined (Downey, 2015). For example:
This result in a SyntaxError because Python expects Cherry and Htun to be variables or valid
expressions, and the syntax itself is incorrect due to the space between them.
(b) Difference Between * and ** Operators in Python
The * operator is used for multiplication and can also be used to repeat sequences such as lists or
strings a specified number of times. The ** operator is used for exponentiation, raising a number
to the power of another (Ramos, 2023). Example:
(c) Displaying an Integer with a Leading Zero
In Python, integers cannot be displayed with a leading zero unless they are specified as strings. If
you try to define an integer with a leading zero, Python will treat it as an octal number (base 8),
but since Python 3, this leads to a SyntaxError when the number is not a valid octal number
(Downey, 2015). Example:
(d) Difference Between type('67') and type(67)
type('67') returns <class 'str'>, indicating that '67' is a string because it is enclosed in quotation
marks. type(67) returns <class 'int'>, indicating that 67 is an integer (Downey, 2015).
Example:
These examples illustrate some common errors and features in Python, such as syntax
mistakes and type distinctions. The difference in usage of operators and data types underscores
the need for careful syntax and understanding Python's type system.
Part 2:
(a) Multiply Age by 2
This program multiplies my age (24) by 2:
Explanation: Multiplying the age by 2 is straightforward, using the arithmetic operator *. This
reflects how arithmetic operations can be performed on integers in Python.
(b) Display City, Country, and Continent
This program displays the name of the city, country, and continent I'm living in:
Explanation: This uses a dictionary to store and display structured data, demonstrating Python's
capability to handle and organize data effectively (W3 Schools, n.d.).
(c) Display Examination Schedule
This program displays the examination schedule for the term:
Explanation: The use of strings to store and print date information shows how textual data is
handled and displayed in Python.
(d) Display Temperature
This program displays the temperature of my country on the day the assignment is attempted:
Explanation: Displaying a simple string illustrates the simplicity of outputting data directly,
which is useful for displaying static or non-computed information.
Learning Outcomes
From executing these tasks, I learned how to use basic data types in Python, such as integers,
strings, and dictionaries. These tasks demonstrate data declaration, arithmetic operations, and
simple output operations using the print() function.
Reference
Downey, A. (2015). Think Python: How to think like a computer. Green Tree Press.
scientist. https://my.uopeople.edu/pluginfile.php/1846111/mod_page/content/73/TEXT%20-
%20Think%20Python%202e%20%282%29.pdf
Ramos, L. P. (2023). Operators and Expressions in Python. Real Python.
https://realpython.com/python-operators-expressions/
W3 Schools. (n.d). Python Dictionaries.
https://www.w3schools.com/python/python_dictionaries.asp