Programming Assignment 1
Programming Assignment 1
A. When I leave out one or both of the quotation marks around my name, it will
result in a syntax error. In Chapter 1. The way of the program, Pp 1.3 informs
us that ' The quotation marks in the program mark the beginning and end of
the text to be displayed, they don’t appear in the results.’ ( Downey, A. (2015).
Think Python: How to think like a computer scientist. Green Tree Press.
https://greenteapress.com/thinkpython2/thinkpython2.pdf
Chapter 1 The Way of the Program, Pp 1.3)
Chat gpt explains the following “Operators are for unpacking elements from iterable
objects and for accepting variable numbers of arguments in function definitions,
respectively’’
The ** operator is used for unpacking keyword arguments in function calls and for
creating dictionaries by unpacking key-value pairs.
It allows you to pass a dictionary of keyword arguments to a function or to merge
dictionaries.” (Chatgpt,
https://chat.openai.com/c/b37ac0a0-072b-4950-8870-6c156cac050f, Downey, A.
(2015). Think Python: How to think like a computer scientist. Green Tree Press.
https://greenteapress.com/thinkpython2/thinkpython2.pdf, Chapter 1, The Way of the
Program)
C. You cannot display an integer with a leading zero like "09" directly. If you try to do
so, you will encounter a syntax error. This is because a leading zero in an integer
literal signifies an octal (base-8) number in Python. ( ChatGPT,
https://chat.openai.com/c/b37ac0a0-072b-4950-8870-6c156cac050f)
The quotes around '67' make it a string, while the absence of quotes around 67 makes
it an integer. Python recognizes and treats these types differently.
Chapter 1. The way of the program, Pp 1.5 Values and types explains the different types.
“A value is one of the basic things a program works with, like a letter or a number. Some
values we have seen so far are 2, 42.0, and 'Hello, World!'.
These values belong to different types: 2 is an integer, 42.0 is a floating-point number, and
'Hello, World!' is a string, so-called because the letters it contains are strung together.
If you are not sure what type a value has, the interpreter can tell you:
>>> type(2)
<class 'int'>
>>> type(42.0)
<class 'float'>
>>> type('Hello, World!')
<class 'str'>
In these results, the word “class” is used in the sense of a category; a type is a category of
values." ( Downey, A. (2015). Think Python: How to think like a computer scientist. Green
Tree Press. https://greenteapress.com/thinkpython2/thinkpython2.pdf, Chapter 1, The Way of
the Program)
Part 2:
A. age = 20
results = age * 2
print(results)
40
What I have learned is that when you use an input by a print statement you can get the output
you are looking for. Age is assigned the integer 20, The function then uses the print()
function to output the values of these variables in a formatted format .
The * Operator was also used to multiply the integer by 2 which is the age.
B. city = "Johannesburg"
>>> country = "South Africa"
>>> continent = "Africa"
>>> print(f"I am living in {city}, {country}, {continent}.")
I am living in Johannesburg, South Africa, Africa.
The City, Country, and Continent were assigned the string "Johannesburg", "South Africa",
"Africa". The function then uses the print() function to output the values of these three
variables in a formatted string. The curly braces {} are placeholders for the values that will be
passed through the .format() method.
I learned to use the start and end date as inputs and displayed an exam schedule. November
is used as a string
D. temperature = 29
print("temperature in Johannesburg the day I attempted the assignment:",
temperature, "degrees Celsius")
temperature in Johannesburg the day I attempted the assignment: 29 degrees Celsius
I took the temperature and then displayed the temperature for my city.
References:
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree Press.
https://greenteapress.com/thinkpython2/thinkpython2.pdf (Chapter 1)
ChatGBT (https://chat.openai.com/c/b37ac0a0-072b-4950-8870-6c156cac050f)