CS1101 Discussion Assignment Unit 1 PDF

Title CS1101 Discussion Assignment Unit 1
Course Programming Fundamentals
Institution University of the People
Pages 2
File Size 73.1 KB
File Type PDF
Total Downloads 212
Total Views 561

Summary

Type the statements below into your Python interpreter. For each statement , copy the output into your Discussion Assignment and explain the output. Compare it with any similar examples in the textbook, and describe what it means about your version of Python.>>> print 'Hello, Wo...


Description

Type the statements below into your Python interpreter. For each statement, copy the output into your Discussion Assignment and explain the output. Compare it with any similar examples in the textbook, and describe what it means about your version of Python. >>> print 'Hello, World!' >>> 1/2 >>> type(1/2) >>> print(01) >>> 1/(2/3)

>>> print 'Hello, World!' SyntaxError: Missing parentheses in call to 'print'. Did you mean print('Hello, World!')?

Here, the output displays a syntax error for missing parentheses. I am using Python 3 where the parentheses indicate that print is a function. In Python 2, the print statement is slightly different; it is not a function, so it doesn’t use parentheses. In section 1.3 of the textbook, there's a similar example. >>> 1/2 0.5

Python provides operators. The operator / performs division. A similar example is in section 1.4 of the textbook. >>> type(1/2)

A similar example is in section 1.5 of the textbook. In this result, the word “class” is used in the sense of a category; a type is a category of values. Integers belong to the type int, strings belong to str and floating-point numbers belong to float. From the previous statement, we saw the output is a floating-point number; so it belongs to the float class. >>> print(01) SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers

In math notation, leading zeros are ok, as in 02. But in Python, it displays syntax error. As it's stated in the output, leading zeros in decimal integer literals are not permitted in Python. There's a similar exercise in the Chapter 1 exercise 1.1 section of the textbook. >>> 1/(2/3) 1.5

Python follows arithmetic formulas and conventions usually. So, using brackets and division operators between numbers in this statement, after mathematic computation, the output is a floating-point number....


Similar Free PDFs