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

Understanding Python Fundamentals

The document covers Python fundamentals, focusing on common errors, operators, and data types. It explains the implications of syntax issues, the difference between multiplication and exponentiation, and the significance of data types through practical examples. Additionally, it highlights the author's learning experience through experimentation and programming exercises.

Uploaded by

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

Understanding Python Fundamentals

The document covers Python fundamentals, focusing on common errors, operators, and data types. It explains the implications of syntax issues, the difference between multiplication and exponentiation, and the significance of data types through practical examples. Additionally, it highlights the author's learning experience through experimentation and programming exercises.

Uploaded by

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

Understanding Python Fundamentals

Part 1: Learn from Your Mistakes


In this section, we explore common errors encountered while experimenting with Python, analyze their
causes, and understand their implications.

a. If you are trying to print your name, what happens if you leave out one of the quotation marks or
both, and why?
Code Example:
print("John) # Missing one quotation mark
print(John) # Missing both quotation marks
Explanation:
 Missing one quotation mark results in a SyntaxError because the string is not properly closed.
 Missing both quotation marks will cause a NameError as Python interprets John as a variable,
which is undefined.

b. What is the difference between * and ** operators in Python?


Code Example:
# Multiplication operator
result1 = 5 * 3 # Expected output: 15

# Exponentiation operator
result2 = 5 ** 3 # Expected output: 125

print("5 * 3 =", result1)


print("5 ** 3 =", result2)
Explanation:
 The * operator performs multiplication, producing the product of two numbers.
 The ** operator is for exponentiation, raising the base to the power of the exponent.

c. In Python, is it possible to display an integer like 09? Justify your answer.


Code Example:
num = 09 # SyntaxError
Explanation:
Python does not allow leading zeros in integer literals as they are reserved for octal (base-8)
representations in earlier Python versions. In Python 3, using 09 produces a SyntaxError.

d. Run the commands type('67') and type(67). What is the difference in the output and why?
Code Example:
print(type('67')) # Output: <class 'str'>
print(type(67)) # Output: <class 'int'>
Explanation:
 '67' is a string because it is enclosed in quotes, indicating a sequence of characters.
 67 is an integer as it represents a numerical value without quotes.

Part 2: Python Programs


a. Multiply your age by 2 and display it.
Code Example:
age = 25
result = age * 2
print("Age multiplied by 2:", result)
Explanation:
This code multiplies the variable age by 2 and prints the result.

b. Display the name of the city, country, and continent you are living in.
Code Example:
city = "New York"
country = "USA"
continent = "North America"
print("City:", city)
print("Country:", country)
print("Continent:", continent)
Explanation:
This program stores the city, country, and continent in variables and prints them in a readable format.

c. Display the examination schedule of this term.


Code Example:
start_date = "November 20, 2024"
end_date = "December 15, 2024"
print("Examination schedule: From", start_date, "to", end_date)
Explanation:
The code uses variables to store and display the start and end dates of the examination schedule.

d. Display the temperature of your country on the day the assignment is attempted.
Code Example:
temperature = 18 # Celsius
print("Today's temperature:", temperature, "°C")
Explanation:
This program demonstrates how to display the temperature using a variable.

What I Learned
From these experiments, I gained a deeper understanding of Python's syntax and functionality.
Experimenting with errors clarified how Python identifies and reports issues like SyntaxError and
NameError. Exploring operators reinforced their functionality, particularly the distinction between
multiplication (*) and exponentiation (**). I also learned the significance of proper data types, as seen in
the difference between type('67') and type(67).
In Part 2, I applied fundamental Python concepts to practical problems. Writing programs with variables
helped me understand how data is stored and displayed. These exercises enhanced my debugging skills
and reinforced the importance of precise syntax and logical flow.

References
 Downey, A. (2015). Think Python: How to think like a computer scientist. Green Tree Press.
https://greenteapress.com/thinkpython2/thinkpython2.pdf
 Python Software Foundation. (n.d.). Python Documentation. Retrieved from
https://docs.python.org

You might also like