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

Assignment 1

This document contains sample Python code snippets that demonstrate various Python concepts like string formatting, variables, operators, and data types. The code examples show how to handle syntax errors from missing quotation marks, use multiplication and exponentiation operators, display integers with leading zeros as strings, determine data types with and without quotes, multiply and print an age, display variables for location details, and print an examination schedule with start and end dates that include real temperature data for Pakistan on the day the assignment was attempted.

Uploaded by

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

Assignment 1

This document contains sample Python code snippets that demonstrate various Python concepts like string formatting, variables, operators, and data types. The code examples show how to handle syntax errors from missing quotation marks, use multiplication and exponentiation operators, display integers with leading zeros as strings, determine data types with and without quotes, multiply and print an age, display variables for location details, and print an examination schedule with start and end dates that include real temperature data for Pakistan on the day the assignment was attempted.

Uploaded by

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

Part 1:

Question a:

If you leave out one or both of the quotation marks while trying to print your name in Python,

you will encounter a SyntaxError. This is because Python expects strings to be enclosed in either

single (' ') or double (" ") quotation marks

Ref: (Python Software Foundation, 2020).

Question b:

In Python, the * operator is used for multiplication, while the ** operator is used for

exponentiation

Ref: (Python Software Foundation, 2020).

Question c:

In Python, it's not possible to display an integer like 09 because numbers starting with 0 are

treated as octal (base 8). Since 9 is not a valid octal digit, it would result in a SyntaxError. To

display leading zeros with integers, you would need to convert the integer to a string and then

format it accordingly
Ref: (Python Software Foundation, 2020).

Question d:

When you run type('67'), it will return the type str because you've enclosed the digits in single

quotes, making it a string. When you run type(67), it will return the type int because it's a plain

integer without quotes

Ref: (Python Software Foundation, 2020).

Part 2:

Question a:

To multiply your age by 2 and display it in Python, you can use the following code

age = 16

result = age * 2

print(result)

Ref: (Python Software Foundation, 2020)

Question b:

To display the name of the city, country, and continent, you can define variables for each and

print them
city = "New York"

country = "USA"

continent = "North America"

print("City:", city)

print("Country:", country)

print("Continent:", continent)

Ref: (Python Software Foundation, 2020)

Question c:

To display the examination schedule, you can define variables for the starting and ending day

and print them

start_date = "2023-12-10"

end_date = "2023-12-20"

print("Examination Schedule:")

print("Start Date:", start_date)

print("End Date:", end_date)

Ref: (Python Software Foundation, 2020)


Question d:

To display the temperature of Pakistan on the day I attempted this assignment, I included real-

time temperature data, with Pakistan experiencing a temperature of 37 degrees Celsius on this

particular day. I used this data in my Python program to provide an accurate temperature reading.

Here's the Python code snippet that accomplishes this:

country = "Pakistan"

temperature = 37

print(f"The temperature in {country} today is {temperature} degrees Celsius.")

References:

Python Software Foundation. (2020). Python 3.8.3 documentation: The Python Language

Reference. https://docs.python.org/3/reference/index.html

You might also like