Python Quiz 1

PYTHON QUIZ 1

CONGRATULATIONS! YOU HAVE COMPLETED PYTHON QUIZ 1. YOU HAVE %%SCORE%% TRUE ANSWERS OUT OF %%TOTAL%% QUESTIONS. YOUR SCORE IS %%PERCENTAGE%%. %%RATING%%
Your answers are highlighted below.
Question 1
How many stars does this program prints?
i=7
while i>0:
  i-=3
  print("*")
  if i<=2:
    break
  else:
    print("*")
A
0
B
4
C
2
D
1
E
3
Question 2
How to access "bear" item in list x? 
x= ["eagle","bear","wolf"]
A
x[2]
B
x[1]
C
x[-2]
D
x[0]
E
x[-1]
Question 3
Which python regular expression is WRONG?
A
\w - Matches word characters.
B
$ - Matches end of line.
C
[...] - Matches any single character in brackets.
D
^ - Matches beginning of line.
E
\d - Matches strings.
Question 4
Which one is a python set?
A
{"eagle","bear","wolf"}
B
"eagle","bear","wolf"
C
(["eagle","bear","wolf"])
D
["eagle","bear","wolf"]
E
("eagle","bear","wolf")
Question 5
What is the output of this python code?
list1 = []
for x in range(1,10,1):
	list1.append(x-2)
print(list1)
A
[0, 2, 4, 6]
B
[1, 2, 3, 4, 5, 6, 7]
C
[0, 1, 2, 3, 4, 5, 6, 7, 8]
D
[-1, 1, 2, 3, 4, 5, 6, 7]
E
[-1, 0, 1, 2, 3, 4, 5, 6, 7]
Question 6
Which method is used to get list of dictionary keys?
A
dict.values()
B
none of them
C
dict.keys()
D
dict.items()
E
dict.values()
Question 7
If the output of the below code is "I like dogs.", the method used in the blank part will be ...
txt = "I like cats."
x = txt.--?--("cats", "dogs")
print(x)
A
join
B
strip
C
replace
D
split
E
index
Question 8
How can we access to "g" letter in the below list?
list = [10, [‘aa’, ‘bb’, [‘life’, ‘is’, ‘good’], ‘cc’], 33]
A
list[0][2][2][0]
B
list[1][1][2][0]
C
list[1][2][2][0]
D
list[1][2][1][1]
E
list[1][2][2][1]
Question 9
How to print "I love Python!" with a python code?
A
print(I love Python!)
B
print "I love Python!"
C
print("I love Python!")
D
all of them
E
print(I love Python!):
Question 10
With which python method we convert the letters of a string to upper case?
A
lower()
B
upper()
C
up()
D
convert()
E
down()
Question 11
Which commands combine the items of list x with "dash" between each item?
A
join("-")
B
none of them
C
"-".join(x)
D
join(-)
E
-.join(x)
Question 12
What is the output of this python code and python function?
numbers1 = {10,1,20,2,3}
numbers2 = {1,2,3,4}
print(numbers1.issuperset(numbers2))
A
{10,1,20,2,3}
B
False
C
{1,2,3,4}
D
None of them
E
True
Question 13
To compare two values in python, we use ... operator.
A
%
B
||
C
//
D
&
E
==
Question 14
Which python method deletes all the items in a set?
A
clear()
B
delete()
C
remove()
D
empty()
E
del()
Question 15
What is the result of this python code?
numbers1 = {3,4,5}
numbers2 = {12,17,56,80,92}
print(numbers1.isdisjoint(numbers2))
A
True
B
0
C
False
D
{3,4,5}
E
{12,17,56,80,92}
Question 16
Which one can Not be a Python Variable Name?
A
_Count
B
Count
C
20count
D
count5
E
none of them
Question 17
If the output of the below python code is [5, 10, 15, 20, 25], what is the missing part?
list=[]
for x in range( --?-- ):
	list.append(x)
print(list)
A
5, 30, 5
B
0, 25, 10
C
0, 30, 2
D
5, 20, 5
E
0, 30, 10
Question 18
What is the Output of This Python Code?
list = [ "Aragorn", "Arwen", "Gimli"]
x=len(list)
num = [10,15,22,10]
y=num.count(10)
z=x*y
print(z)
 
A
8
B
2
C
4
D
6
E
12
Question 19
How to access "eagle", "bear" and "wolf" items in list x? x= ["eagle","bear","wolf", "lion", "tiger"]
A
x[-1:-3]
B
x[:3]
C
x[:2]
D
x[1:3]
E
x[3:]
Question 20
How to add "This is x code" comment in a python code?
A
*This is x code
B
//This is x code
C
-This is x code
D
/This is x code
E
#This is x code
Once you are finished, click the button below. Any items you have not completed will be marked incorrect. Get Results
There are 20 questions to complete.