NEW
Font size
WorksheetsPython Quiz
Total questions: 45
Worksheet time: 23mins
Which statement is incorrect
a=!b
a!=b
a=[1,2,3]
B=(9,6,5)
Output? :
a = "You're Pretty"
Print(a)
You're Pretty
"You're Pretty"
a
NameError: name 'Print' is not defined
What is the output for the below program:
A="Hyperboloid"
print(len("A")
11
911
12
1
What does my_list.append(5) do?
Removes the last element from the list.
Creates a new list with only the number 5.
Appends the number 5 to the end of the list.
Adds 5 to the beginning of the list.
Used to define a function:
Def
def
define
Define
What is the output for the below program:
for i in range(10<11):
print(i)
10
11
0
Error: logical operators cannot be used inside range()
[1,2,3,4,5,6,7,8,9,10]
1,2,3,4,5,6,7,8,9,10
[0,1,2,3,4,5,6,7,8,9]
0,1,2,3,4,5,6,7,8,9
Output?
Error
[1, 2, 3, [4], [5]]
[1, 2, 3, 4, 5]
[1, 2, 3, [4, 5]]
What is the output for the program?
ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ
Error:False can't be used inside the while loop
Red
Red
Red
Red
Red
Red
Red
Output?
Positive
Negative
Zero
Positive Zero
Can you modify the elements of a tuple after it has been created?
Yes
No
What is the output for the program?
1
2
3
4
1
3
5
1
3
Error:Boolen values can't be used inside range()
Output?
8
16
Indentation Error
Runtime Error
How can you reverse the order of characters in the string "Hello"?
"Hello".invert()
reverse("Hello")
"Hello".reverse()
"Hello"[::-1]
What is the output for the program?
1
1.line()
1.0
Attribute Error
What is the output of the expression : 3*1**3
27
9
3
1
Which of these is not a core data type?
Lists
Dictionary
Tuples
Class
print(input("Enter a string")[::-1])
Reverses the given string to the input
Error : input() cannot be used inside print ()
What will be the output for the below program:
print(100**1.5)
3.162277
100.0
1000.0
1.5
Output?
Error
[1,2,3,4,5]
[1,2,3,4,5,6]
None of these
What will be the output for the below program?
print(8**1**98)
1
31828687130226345097944463881396533766429193651030253916189694521162207808802136034115584
98
8
What is the primary advantage of using a tuple over a list in certain situations?
Lists have better performance.
Lists are immutable.
Tuples can have more elements
Tuples are more memory-efficient.
Output?
[2,3,4,5]
[3,4,5]
[4,5]
Error : negative index cannot be used as start value
What is the result of the following operation?
(5, 7, 9)
[(1, 2, 3), (4, 5, 6)]
(1, 2, 3, 4, 5, 6)
Error: Tuple cannot be modified as Tuple is immutable
What is Python?
A compiled programming language.
A database management system.
A markup language.
An interpreted scripting language
What is the output for the program?
can't divisible by 4
divisible by 4
Can't divisible by 4
Error
In Python, which of the following is a valid variable name?
2numbers
_myVar
my-var
first name
What is the purpose of the break statement in a loop?
To continue to the next iteration
To skip the current iteration.
To end the entire program.
To exit the loop prematurely.
What is a function in Python?
A built-in module.
A reusable block of code.
A data type.
A reserved keyword.
Which mode is used to open a file for writing in Python?
'o'
'w'
'r'
'x'
What is the difference between a list and a tuple in Python?
Lists are mutable, tuples are immutable
Lists are ordered, tuples are unordered
Lists can have different data types, tuples cannot
All the above
What is a module in Python?
A collection of functions.
A file containing Python code that defines variables and functions.
A built-in data type.
A loop structure.
What is the difference between range(5) and range(1, 6)?
No difference
range(5) includes 5, range(1, 6) does not
range(1, 6) includes 5, range(5) does not
In range(1,6) the range will conclude with 6 whereas in range(5) the range will conclude with 5
How do you create an infinite loop using while?
While True:
while true:
While true:
while True:
What is the purpose of the range() function in a for loop?
Defines the loop condition
Generates a sequence of numbers
Specifies the loop iteration step
Runs the loop infinitely
Which statement is incorrect?
X=Tuple(input("Enter Tuple"))
X=List(input("Enter List"))
X=str(input("Enter a string"))
X=int(input("Enter a number"))
Which statement is incorrect?
print("g"[::-1])
print(' ,"&£@(-__-):')
if h<6:
if a in x
Can a compiler have the ability to run this code:
for i in range(10000,0,1):
Yes
No
Impossible for low end compilers
What is the output for the program?
(2,4,5,6,7,9)
Error : Tuple cannot be modified using list operatoions
[(2,4,6,7),9]
[2,4,5,6,7,9]
What is the main advantage of using lambda functions in Python?
They provide a concise way to create small anonymous functions.
They can be used only for mathematical operations.
They are more memory-efficient.
They allow for multi-line code blocks.
What is an iterator in Python?
A special type of list.
An object that can be iterated (looped) over.
A function that returns a sequence of numbers.
A built-in data type.
In Python, how does a variable declared inside a function differ from one declared outside a function?
Variables inside a function can only be accessed from other functions.
Variables inside a function are global by default.
There is no difference.
Variables inside a function have local scope.
What is recursion in Python?
A method for defining class attributes.
A loop structure.
A way to handle exceptions.
A function that calls itself.
What will be the output for the below program:
print("Hello*3")
HelloHelloHello
HelloHelloHellO
Error
Hello*3
What character is used to indicate a single-line comment in Python?
//
/* */
--
#
