NEW
Font size
Worksheets2F-3 | Python Quiz | 14/11/2024
Total questions: 20
Worksheet time: 30mins
What will the following code output? print("Python", "Quiz", sep="*", end="123")
Python*Quiz123
Python*Quiz*123
Python * Quiz123
Python-Quiz-123
How can you get integer input from the user and add 10 to it in one line of code?
input() + 10
str(input()) + 10
int(input()) + 10
float(input()) + 10
What is the result of the expression 9 // 4.0 in Python?
2.0
2
3.0
3
What does the sep parameter in the print() function do when used with multiple string arguments?
Changes the end character
Joins the strings with the given separator
Adds a space between strings
Causes an error
Which operator can be used to perform floor division in Python?
/
//
%
**
What is the output of print(int("3.5") + 1)?
4.5
4
Error
5
What does print("A" * 3 + "B" * 2) produce as output?
ABBB
AABBB
AAABB
AAABBB
Evaluate this expression: 10 % 4.5
1.0
0.5
1.5
0
What is the output of the following code? print("Python", end="*"); print("is great!")
Python is great!
Python* is great!
Python*is great!
Python-is great!
What is the output of print("Hello" + " " + str(5 * 3))?
Hello15
Hello 15
Hello 153
Error
What happens if you use float(input("Enter a number: ")) and the user inputs a non-numeric string?
0 is returned
The string is converted to 0
An error occurs
The input is ignored
How can you check if a variable num is an integer type in Python?
type(num) == float
num.is_integer()
type(num) == int
num.isdigit()
What does the expression 10 ** (1/2) evaluate to in Python?
2
5
3.16
3.1622776601683795
What will happen if you try to execute int("seven")?
Converts to 7
Error
Converts to 0
Converts to 1
How can you make the following code print "Hello!World!" without changing the text inside the print() function? print("Hello", end="") followed by print("World!")
Add end="!" to the first print() statement
Change end="" to end=" "
Add a semicolon ;
Change the second print() to print(" World")
Which of these will convert a float num to a string representation while limiting the number of decimal places shown to two?
str(num, ".2f")
f"{num:.2}"
f"{num:.2f}"
str.format(num, ".2f")
What will be the output of print("Data" * 2 + "Science")?
DataData Science
DataDataScience
Data*2Science
Data ScienceData
Which of these statements will correctly check if x is even?
if x % 2 == 1:
if x // 2 == 0:
if x % 2 == 0:
if x / 2 == 0:
What is the output of print(2 + 3 * 4)?
20
14
24
18
Which of the following statements correctly creates a comment in Python?
// This is a comment
/* This is a comment */
# This is a comment
<-- This is a comment -->
