COP2273 - Python Programming Exam 1 Study
What is the correct extension of Python files (modules or scripts)?
.py
What is the output from the following fragment? for i in range(2**3): print (i, end=" ")
0 1 2 3 4 5 6 7
In Python, the expression 5.0 // 4.0 evaluates to
1.0
What is the output from the following fragment? y = 10 for x in range(7, 12, 2): y = y*x print (x,y)
11 6930
What is the output from the following fragment? for num in [9, 2, 8, 2, 7]: x, y = num+1, num-1 print(x//y, end="")
13131
What is the output from the following fragment? import math x, y = 7, 0 for i in range(x, x//2, -2): y = y + 3*x//3 + x%3 + math.sqrt(x-3) print(int(y))
20
What is the maximum value that could be represented using 1 byte?
255
________ is a sort of active data type that combines both data and operation.
An object
Program Specification
Deciding exactly what the program will do
A hardware int can represent a larger range of values than a hardware float
False
Every class is an instance of some object.
False
The process of turning an underlying data type into an extension is called evaluation.
False
Converting a float to an int rounds the fractional part of the float.
False (it is truncated)
Testing/Debugging
Finding and fixing errors in the code
Which of the following is true? In the default 200 X 200 GraphWin, the lower-right corner has the coordinates (200, 200). Traditionally, graphics programmers locate the point (0,0) in the upper-right corner of a graphic window. In geometry, a point is a location in space. Given the point (x, y) in a graphic window, the x value represents the vertical location of the point and the y value represents the horizontal.
In geometry, a point is a location in space.
Which of the following is not true? The expression 9.0 + 6.0 evaluates to 15.0. The expression 9 + 6 evaluates to 15. A value's data type determines what operations can be used on it. Integer data type and floating-point data type share the same set of operations.
Integer data type and floating-point data type share the same set of operations. (not true)
Maintenance
Keeping the program up to date
Problem Analysis
Studying the problem to be solved
Implementation
Translating the design into a programming language
Which of the following class is not provided in the graphics module? Oval Rectangle Triangle Circle
Triangle
A function that lives inside an object is invoked using dot-notation.
True
A variable must always be assigned a value before it can be used in an expression.
True
The float type can only represent approximations to real numbers.
True (but idk if it really is)
Design
Writing an algorithm in pseudocode
A special method that creates a new object (or instance) of a class is called a
constructor
Which of the following is a Python keyword (or reserved word)? elif true boolean export
elif
Which of the following is not a legal identifier in Python? first name _name name1 fName
first name
Which is the correct Python command to use every method (or command) defined in a library module called graphics without having to preface them with the module name graphics?
from graphics import *
Which of the following is not a built-in function? print() help() greet() input()
greet()
Which of the following is different from the rest? object function operation method
object
Which of the following statement is the best in Python? pennies = input("How many pennies do you have? ") pennies = eval(input("How many pennies do you have? ")) pennies = float(input("How many pennies do you have? ")) pennies = int(input("How many pennies do you have? "))
pennies = int(input("How many pennies do you have? ")). This is because we know the entry will be an integer.
