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

Python Assignment

The document outlines common errors in Python programming, such as missing quotation marks leading to SyntaxError and NameError, and explains the difference between operators like * and **. It also discusses the implications of leading zeros in integers and the distinction between string and integer types. Additionally, it provides examples of simple Python programs that perform basic operations like multiplying age, displaying location information, and showing an examination schedule.

Uploaded by

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

Python Assignment

The document outlines common errors in Python programming, such as missing quotation marks leading to SyntaxError and NameError, and explains the difference between operators like * and **. It also discusses the implications of leading zeros in integers and the distinction between string and integer types. Additionally, it provides examples of simple Python programs that perform basic operations like multiplying age, displaying location information, and showing an examination schedule.

Uploaded by

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

Python Assignment: Frequently Occurring Errors and Programs

Part 1: Frequently Occurring Errors


(a) Printing a name with missing quotation marks
Code:

print("Musa Bello) # Missing closing quotation mark


print(Musa Bello) # Missing both quotation marks

Output and Explanation:

1. SyntaxError: unterminated string literal (detected at line X)


Missing a closing quotation mark leads to a syntax error because Python cannot determine
where the string ends.

2. NameError: name 'Musa' is not defined


Without quotation marks, Python interprets Musa as a variable name, which hasn’t been
defined.

(b) Difference between * and ** Operators


Code:

result_multiply = 3 * 3
result_exponent = 3 ** 3
print("3 * 3 =", result_multiply)
print("3 ** 3 =", result_exponent)

Output and Explanation:

3*3=9
3 ** 3 = 27

Explanation:
- * performs multiplication.
- ** raises a number to the power of another (exponentiation).
(c) Is it possible to display an integer like 09?
Code:

print(09) # Attempt to display an integer with a leading zero

Output and Explanation:

SyntaxError: leading zeros in decimal integer literals are not permitted.

Explanation: In Python, leading zeros are not allowed in integers because it creates
ambiguity with octal (base-8) numbers.

(d) Difference between type('67') and type(67)


Code:

print(type('67')) # String type


print(type(67)) # Integer type

Output and Explanation:

<class 'str'>
<class 'int'>

Explanation: '67' is treated as a string (text data), while 67 is treated as an integer (numeric
data).

Part 2: Python Programs


(a) Multiply age by 2 and display it
Code:

age = 22
result = age * 2
print("Your age multiplied by 2 is:", result)

Output:

Your age multiplied by 2 is: 44


(b) Display city, country, and continent
Code:

city = "Sokoto"
country = "Nigeria"
continent = "Africa"
print("City:", city)
print("Country:", country)
print("Continent:", continent)

Output:

City: Sokoto
Country: Nigeria
Continent: Africa

(c) Display examination schedule


Code:

start_date = "09 January 2025"


end_date = "12 January 2025"
print("Examination Schedule:")
print("Start Date:", start_date)
print("End Date:", end_date)

Output:

Examination Schedule:
Start Date: 09 January 2025
End Date: 12 January 2025

(d) Display the temperature on the assignment submission day


Code:

temperature = 32 # Example temperature in Celsius


print("Temperature on the day of assignment submission:", temperature, "°C")
Output:

Temperature on the day of assignment submission: 32 °C

You might also like