0% found this document useful (0 votes)
6 views4 pages

PF Assignment 1

The document provides a series of Python code examples demonstrating common syntax errors and correct outputs. It emphasizes the importance of understanding data types, such as strings and integers, and the use of operators like multiplication and exponentiation. Additionally, it highlights lessons learned from running various codes, including the ability to combine integers and strings in print statements.

Uploaded by

promisemelie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

PF Assignment 1

The document provides a series of Python code examples demonstrating common syntax errors and correct outputs. It emphasizes the importance of understanding data types, such as strings and integers, and the use of operators like multiplication and exponentiation. Additionally, it highlights lessons learned from running various codes, including the ability to combine integers and strings in print statements.

Uploaded by

promisemelie
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

PART 1

Input a: >>print ('Davina)


Output: >>SyntaxError: unterminated string literal (detected at line 1)

Explanation: As experimented above I left out one quotation mark which resulted in a syntax
error. As we progress through our academics it is important to learn from our little mistakes just
like I left one quotation mark, in future when I will make projects or write code, I will carefully
proofread the syntax before printing the output.

Input b1: >>2*2


Output: >>4
Input b2: >>2**2
Output: >>4

Explanation: In the above example we ran two codes with * and ** operators in which *
operator is used to multiply the values and ** operator is exponentiation which raises number to
a power but in above example both of the answers are same, Referring to the book it used the
exponentiation operator with an addition operator which raised the output of multiplied values
with the value 4 as an example below to which the output was 8 different from the one we
performed earlier:
Input b3: >>2**2+4
Output: >>8

Input c1: >>09


Output: >>SyntaxError: leading zeros in decimal integer literals are not permitted; use a 0o
prefix for octal integers

Explanation: No, we cannot print the integer 09 in python3 because leading zeros are not
permitted in the environment but if we use 00 integer in the environment it will print the syntax
answer for example below:
Input c2: >>00
Output: >>0

Input d1: >>type ('67')


Output: >><class 'str'>
Input d2: >>type (67)
Output: >><class 'int'>
Explanation: In the above printed syntax we can see that we used the same value but resulted
with different outputs why because the syntax (‘67’) is a string because the value is between the
quotation marks which is used to print a string and the syntax (67) is an integer because we
didn’t use any string but it belongs to the category of integer.

PART 2

Input a>> 20*2


Output: >>40

Input b>> print ('Karachi, Pakistan, Asia')


Output: >>Karachi, Pakistan, Asia
Input c: >> print ('5 June, 2025 to 8 June, 2025’)
Output: >>5 June, 2025 to 8 June, 2025

Input d: >> print ('31-degree Celsius')


Output: >>31-degree Celsius

Lessons learned from the experiments of part 2: The lessons I learned from the part 2 is by
running different codes with different contexts like multiplying my age with the integer 2 (20*2),
as I will progress through the programming fundamentals course the coding parameters will
become difficult and descriptive with each unit, so running one line codes as a starter will help
me to understand the technical terms and syntaxes better. For the output two in which I printed
the name of the city, country and continent where I live helped me to better understand the
syntax because I didn’t run each category separately instead it summed up in one print parameter
and displayed the output correctly >>print ('Karachi, Pakistan, Asia'). The third input in which
it was asked to mention the starting to end day of the final exam of this term I learned that an
integer can also be used within a string of words to output our syntax without getting an error in
the result >> print ('5 June 2025 to 8 June,2025'). And the last output in which it was asked to
print the temperature of my country the lesson I learned from it is same as output three that I can
use integers within a string >> print ('31-degree Celsius').

Reference:
Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree Press.
https://greenteapress.com/thinkpython2/thinkpython2.pdf

You might also like