Python for Beginners
English
Basic
This quiz is meant for beginners to teach and quiz on the basic concepts of Python
Description
Tags
30
Questions
1 min
Per question
8:13
Average time
4.0
Contest Score
4.2
Community Rating
53
Participants
Educational explanations. 👍
Explanations cover why the correct answers are correct.
E.g.: #q1, #q2, #q3, #q9, etc
Question has no correct option :
One of the question has image with following code :
mylist = []
mylist.append(1)
mylist.append(2)
mylist.append(3)
print(mylist[0]) # print 1
print(mylist[1]) # print 2
print(mylist[2]) # print 3
# prints out 1,2,3
for x in mylist:
print(x)
and we are asked : What will be printed on the console when the code is ran ?
Given answer is 1 2 3
But correct answer should be 1 2 3 1 2 3 (in separate line but this feature is not possible in option)
Additionally, some questions have answers inside the given image.
I don't agree with answers like were you have to choose between this kind of options:
– srennigeb rof nohtyP
– "srennigeb rof nohtyP"
because `print()` returns string and so both of them are correct.
Also, question 9. How many types of functions are there in Python?
your answer is 2, but it's wrong. Built-in, UDFs and lambdas. Overall to arguable question.
Explanations have typos and not informative, imho.
2. The comments on the code in the images were meant to give hints rather than correct answers. I will revise that to see if they can be completely taken out or just modified so they give the correct answer.
3. In both Python 2 & 3 the print function returns a string without the double inverted commas. There are ways to make it return the string with inverted commas. The simplest being:
word = 'hello'
print '"' + word + '"'
The answer should be "x equals two!" with an exclamation point, because it has an exclamation point in the print statement.
I also agree that the red background with white text is difficult to read on some of the images. Other than that, most of the questions are good.
Explanation: In Python the format() is used to swap the values of each element
It is incorrect, you swapped values using variable temp. format() is used to formatting strings
str.format(*args, **kwargs)
Perform a string formatting operation. The string on which this method is called can contain literal text or replacement fields delimited by braces {}. Each replacement field contains either the numeric index of a positional argument, or the name of a keyword argument. Returns a copy of the string where each replacement field is replaced with the string value of the corresponding argument.
>>> "The sum of 1 + 2 is {0}".format(1+2)
'The sum of 1 + 2 is 3'
Let's consider this code: https://ideone.com/bzoOp3
x = 5
y = 10
# Now x = 5 and y = 10
print(' x : {}'.format(x)) # x : 5
print(' y : {}'.format(y)) # y : 10
' x : {}'.format(x) evaluates to ' x : 5' ({} replaced with value of x)
' y : {}'.format(y) evaluates to ' y : 10' ({} replaced with value of y)
As you can see, variables didn't swap. So format() is used to formatting strings, not to swap the values of user-defined variables.
I also did look at another code that can swap the values with using any temporary variables which can be found here: https://ideone.com/u4FhH5
You said that correct answer is: (Updated language set: English, French)
Actually the correct answer is: Updated language set: {'English', 'French'}
I removed round brackets and added braces and quotes