3. Functions, Strings & Objects - 25 Questions

# 3. Functions, Strings & Objects

25 Questions
Created by Y. Daniel Liang
Free
##### In this quiz you will be tested about selection statements, which allow a program to choose when to execute certain instructions. For example, a program might choose how to proceed on the basis of the user's input. As you will be able to see, such statements make a program more versatile.
1. What is max(3, 5, 1, 7, 4)?

1
3
7
5

2. What is min(3, 5, 1, 7, 4)?

1
3
5
7

3. What is round(3.52)?

3.5
3
4
5

4. What is round(6.5)?

4
5
6
7

5. What is math.degrees(math.pi / 2)?

0.0
90.0
45.0
30.0

6. What is math.radians(30) * 6?

0.0
1.3434343
3.141592653589793
5.565656

7. What is math.sin(math.pi / 6)?

1.0
1.3434343
3.141592653589793
0.5

8. What is chr(ord('B')))?

A
B
C
D

9. Suppose x is a char variable with a value 'b'. What will be displayed by the statement print(chr(ord(x) + 1))?

a
b
c
d

10. Which of the following statement prints smith\exam1\test.txt?

print("smith\exam1\test.txt")
print("smith\\exam1\\test.txt")
print("smith\"exam1\"test.txt")
print("smith"\exam1"\test.txt")

11. Suppose i is an int type variable. Which of the following statements display the character whose Unicode is stored in variable i?

print(i)
print(str(i))
print(int(i))
print(chr(i))

12. The Unicode of 'a' is 97. What is the Unicode for 'c'?

96
97
98
99

13. What will be displayed by print(ord('z') - ord('a'))?

25
26
a
z

14. The expression "Good " + 1 + 2 + 3 evaluates to ________.

Good123
Good6
Good 123
Illegal expression

15. What will be displayed by the following code?

print("A", end = ' ')
print("B", end = ' ')
print("C", end = ' ')
print("D", end = ' ')

ABCD
A, B, C, D
A B C D
A, B, C, D will be displayed on four lines

16. Suppose s = "Welcome", what is type(s)?

int
float
str
String

17. Suppose s is "Welcome", what is s.upper()?

welcome
WELCOME
Welcome
None of these

18. Suppose s is "\t\tWelcome\n", what is s.strip()?

\t\tWelcome\n
\t\twelcome\n
\t\tWELCOME\n
Welcome

19. To format a number x to 3 digits after the decimal point, use _______.

format(x, "5.3f")
format("5.3f", x)
format(x, "5.4f")
format("5.3f", x)

20. Suppose x is 345.3546, what is format(x, "10.3f")? (note b represents a blank space)

bb345.355
bbb345.355
bbbb345.355
bbb345.354

21. 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
Welcome#111#924.66
Welcome#111#.66
Welcome???#?111#924.66

22. To set the pen size to 5 pixels, use _________.

turtle.setSize(5)
turtle.size(5)
turtle.pensize(5)
turtle.setPenSize(5)

23. To undo the last turtle action, use _________.

turtle.rollback()
turtle.redo()
turtle.undo()
turtle.remove()

24. To set a turtle drawing speed to 5, use _________.

turtle.speed(5)
turtle.setSpeed(5)
turtle.setspeed(5)
turtle.velocity(5)