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

CS 1101-01- Programming Fundamentals – Assignment Submission

The document details an assignment submission for CS 1101-01 Programming Fundamentals, where the student, Olorunleke Ogundele, describes using PythonAnywhere for coding due to not having a laptop. It includes examples of Python code, their outputs, and explanations of syntax differences between Python 2 and Python 3, particularly regarding print statements and division behavior. The student also poses a discussion question about the implications of these changes in programming logic.

Uploaded by

Guru Guru
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 views3 pages

CS 1101-01- Programming Fundamentals – Assignment Submission

The document details an assignment submission for CS 1101-01 Programming Fundamentals, where the student, Olorunleke Ogundele, describes using PythonAnywhere for coding due to not having a laptop. It includes examples of Python code, their outputs, and explanations of syntax differences between Python 2 and Python 3, particularly regarding print statements and division behavior. The student also poses a discussion question about the implications of these changes in programming logic.

Uploaded by

Guru Guru
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/ 3

CS 1101-01: Programming Fundamentals – Assignment Submission

Discussion Forum Unit 1

Name: Olorunleke Ogundele


Course: CS 1101-01 Programming Fundamentals – AY2025-T3
University: University of the People
Week: 1

1. Setting Up the Programming Environment

Since I do not have a laptop, I am using PythonAnywhere, an online Python environment, to


complete this assignment. PythonAnywhere allows running Python scripts directly in a web
browser without requiring software installation.

2. Running the Given Statements and Their Outputs

Statement 1: Printing a Message

print('Hello, World!')

Output:

Hello, World!

Explanation:

• This prints the text "Hello, World!" to the console.

• The correct syntax in Python 3 requires parentheses with print().

• If the statement were written as print 'Hello, World!' (Python 2 style), it would cause a
SyntaxError in Python 3.

Statement 2: Performing Division

print(1/2)

Output:

0.5

Explanation:
• Python 3 automatically performs floating-point division when using /, even if both numbers are
integers.

• In Python 2, 1/2 would return 0 because it performed integer division by default. To get 0.5 in
Python 2, we would need to write 1.0/2 or 1/2.0.

Statement 3: Checking Data Type

print(type(1/2))

Output:

<class 'float'>

Explanation:

• The division 1/2 returns 0.5, which is a floating-point number (float).

• type() is a built-in Python function that returns the data type of a variable or value.

• In Python 3, division always results in a float unless using // for integer division.

Statement 4: Printing an Integer with Leading Zero

# print(01) # This would cause an error

Output:

SyntaxError: invalid token

Explanation:

• In Python 3, numbers cannot have a leading zero unless they are written in octal (base-8)
format (e.g., 0o1 for octal 1).

• In Python 2, writing print(01) would have been valid because it interpreted 01 as an octal
number (1 in decimal).

Statement 5: Complex Division Operation

print(1/(2/3))

Output:
1.5

Explanation:

• The expression is evaluated step by step:

• 2/3 = 0.6667 (floating-point result)

• 1 / 0.6667 = 1.5

• Since division in Python 3 always results in a float, the final result is 1.5.

3. Comparison with Textbook and Python Version Differences

• The textbook examples mostly use Python 3 syntax, but some online resources might still use
Python 2, which has differences.

• Key changes in Python 3 vs. Python 2:

• print statement: Requires parentheses in Python 3 (print('Hello')).

• Division: / always returns a float in Python 3, while it performed integer division in Python 2.

• Leading Zeros: Numbers with leading zeros are invalid in Python 3, unlike in Python 2, where
they were treated as octal.

4. Discussion Question for Classmates

"Python 3 changed the division behavior so that 1/2 returns 0.5 instead of 0. What are the
advantages and disadvantages of this change in programming logic? How might it affect real-
world applications?"

5. Conclusion

• I successfully completed the assignment using PythonAnywhere since I do not have a laptop.

• I identified syntax differences between Python 2 and Python 3.

• I ran the code, analyzed the output, and explained the results technically.

• I formulated a discussion question to engage classmates.

End of Assignment

You might also like