PYTHON SET 1 FINAL
Which of the following is the correct expression of character 4?
"4" '4'
A Python line comment begins with ________.
#
Python syntax is case-sensitive.
True
What is the value of the following expression? True or True and False
True
Choose all possible ways to run a Python program test.py:
Use the command: python test.py Use "Run Module" from IDLE editor that has test.py loaded
Suppose s is "Welcome", what is s.upper()?
WELCOME
The format function returns _______.
a str
The following code displays ___________. temperature = 50 if temperature >= 100: print("too hot") elif temperature <= 40: print("too cold") else: print("just right")
just right
Choose all the valid identifiers below:
mile1 MILE Y_5
Which of the following is equivalent to x != y?
not (x == y) x > y or x < y
Check all the correct statement using print function.
print("Hello") print(135) print("135")
What is y after the following statement is executed? x = 0 y = 5 if x > 0 else -5
-5
random.randint(0, 1) returns ____________.
0 or 1
The function range(5) return a sequence ______________.
0, 1, 2, 3, 4
What is the output of the following? balance = 10 while True: if balance < 9: break balance = balance - 9 print(balance)
1
One gigabyte is approximately ________ bytes.
1 billion
To following code reads two number. Which of the following is the correct input for the code? x, y = eval(input("Enter two numbers: "))
1, 2
What is the result of 45 // 4?
11
2 * 3 ** 2 evaluates to __________.
18
What will be displayed by the following code? x, y = 1, 2 x, y = y, x print(x, y)
2 1
Choose all of the following expressions that result in 8 or 8.0
2**3 math.pow(2,3) 2*2*2
What will be displayed by print(ord('z') - ord('a'))?
25
What will be displayed by the following code? x = 1 x = 2 * x + 1 print(x)
3
What will be displayed when the following code is executed? number = 6 while number > 0: number -= 3 print(number, end = ' ')
3 0
What is the output for y? y = 0 for i in range(10, 1, -2): y += i print(y)
30
Which of the following expression results in a value 1?
37%6
What is x after the following statements? x = 2 y = 1 x *= y + 1
4
If x = 0.428, what is the result of print(format(x,' .2%'))
42.80%
What is the output for y? y = 0 for i in range(0, 10): y += i print(y)
45
Which of the following expressions return True.
6>=6 5 < 6 True
What is max(3, 5, 1, 7, 4)?
7
What is the value of i printed? j = i = 1 i += j + j * 5 print("What is i?", i)
7
How many times is the print statement executed? for i in range(10): for j in range(8): print(i * j)
80
The equal comparison operator is __________.
==
What is chr(ord('A'))?
A
What will be displayed by the following code? print("A", end = ' ') print("B", end = ' ') print("C", end = ' ') print("D", end = ' ')
A B C D
___________ translates high-level language program into machine language program.
A compiler
Which of the following code is correct? A. print("Programming is fun") print("Python is fun") B. print("Programming is fun") print("Python is fun") C. print("Programming is fun)print("Python is fun") D.print("Programming is fun)print("Python is fun")
B
Which of the following loops correctly computes 1/2 + 2/3 + 3/4 + ... + 99/100? A: sum = 0 for i in range(1, 99): sum += i / (i + 1) print("Sum is", sum) B: sum = 0 for i in range(1, 100): sum += i / (i + 1) print("Sum is", sum) C: sum = 0 for i in range(1.0, 99.0): sum += i / (i + 1) print("Sum is", sum) D: sum = 0 for i in range(99): sum += i / (i + 1) print("Sum is", sum)
B
Which of the following loops prints "Welcome to Python" 10 times? A: for count in range(1, 10): print("Welcome to Python") B:for count in range(0, 10): print("Welcome to Python") C:for count in range(1, 11): print("Welcome to Python") D:for count in range(1, 12): print("Welcome to Python")
B C
Choose the correct statements:
It is best to use for loops for counter controlled loops. It is best to use while loops for sentinel controlled loops. Sometimes, an infinite loop is needed
The following loop displays _______________. for i in range(1, 11): print(i, end = " ")
Nothing due to Indentation Error
What will be displayed by the following code? ? (note ? represents a blank space) print(format("Welcome", "10s"), end = '#') print(format(111, "4d"), end = '#') print(format(924.656, "3.2f"))
Welcome???#?111#924.66
You can place the line continuation symbol __ at the end of a line to tell the interpreter that the statement is continued on the next line.
\
Why do computers use zeros and ones?
because digital devices have two stable states and it is natural to use one state for 0 and the other for 1.
Analyze the following code and choose all the correct statements. count = 0 while count < 100: # Point A print("Welcome to Python!") count += 1 # Point B # Point C
count < 100 is always True at Point A count < 100 is always False at Point C
What function do you use to read a number?
eval(input("Enter a number"))
To format a number x to 3 digits after the decimal point, use _______.
format(x, "5.3f")
Suppose isValid is a boolean variable, which of the following is the correct and best statement for testing if isValid is true.
if isValid :
How many times will the following code print "Welcome to Python"? count = 0 while count < 10: print("Welcome to Python")
infinite number of times
In Python, a syntax error is detected by the ________ at _________.
interpreter/at runtime
What is the number of iterations in the following loop: for i in range(1, n): # iteration code
n-1
Suppose x = 1, y = -1, and z = 1. What will be displayed by the following statement? if x > 0: if y > 0: print("x > 0 and y > 0") elif z > 0: print("x < 0 and z > 0")
nothing displayed
To generate a random integer between 1 and 10, use ________________.
random.randint(1, 10) random.randrange(1, 11)
Which of the following function(s) is(are) incorrect?
range(0, 3.5) range(2.5, 4.5)
Which of the following functions return 4.
round(3.9)
To add number to sum, you write
sum += number sum = sum + number
The time.time() returns ________________ .
the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time)
To draw a circle of diameter 20 with red color, use _________.
turtle.dot(20,"red")
To move the turtle to a point at (4, 5), use ___________.
turtle.goto(4, 5)
To set the pen size to 5 pixels, use _________.
turtle.pensize(5)
To show the current location and direction of the turtle object, use ___________.
turtle.showturtle()
Assume x = 4 and y = 5, Which of the following is true?
x < 5 or y < 5
What is the output of the following code? x = 0 if x < 4: x = x + 1 print("x is", x)
x is 1
What is the output of the following code? x = 0 while x < 4: x = x + 1 print("x is", x)
x is 4
What is ord("B") ?
66
Suppose x is 1. What is x after x -= 1?
0
Analyze the following code: Code 1: number = eval(input("Enter number: ")) if number % 2 == 0: even = True else: even = False Code 2: number = eval(input("Enter number: ")) even = number % 2 == 0
Both Code 1 and Code 2 are correct
The expression "Test " + 1 + 2 + 3 evaluates to ________.
Ilegal Expression
What will be displayed by the following code? ch = 'F' if ch >= 'A' and ch <= 'Z': print(ch)
F
What will be displayed by the following code? isCorrect = False print("Correct" if isCorrect else "Incorrect")
Incorrect