CS 1101-01- Programming Fundamentals – Assignment Submission
CS 1101-01- Programming Fundamentals – Assignment Submission
print('Hello, World!')
Output:
Hello, World!
Explanation:
• If the statement were written as print 'Hello, World!' (Python 2 style), it would cause a
SyntaxError in Python 3.
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.
print(type(1/2))
Output:
<class 'float'>
Explanation:
• 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.
Output:
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).
print(1/(2/3))
Output:
1.5
Explanation:
• 1 / 0.6667 = 1.5
• Since division in Python 3 always results in a float, the final result is 1.5.
• The textbook examples mostly use Python 3 syntax, but some online resources might still use
Python 2, which has differences.
• 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.
"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 ran the code, analyzed the output, and explained the results technically.
End of Assignment