Foundation Course in
Python
Assessment 1
Assessment 1:
Q1. Which of below statements are valid and will print foo’bar
A) Print ('foo\'bar‘)
B) Print ('foo''bar‘)
C) Print ("foo'bar“)
D) Print ('foo'bar‘)
E) Print ("""foo'bar""“)
Note: Multiple answers are correct.
Assessment 1:
Q1. Which of below statements are valid and will print foo’bar
A) Print ('foo\'bar‘)
B) Print ('foo''bar‘)
C) Print ("foo'bar“)
D) Print ('foo'bar‘)
E) Print ("""foo'bar""“)
Note: Multiple answers are correct.
Assessment 1:
Q2. What is the data type of print(type(10))
A) Float
B) Integer
C) String
D) List
Assessment 1:
Q2. What is the data type of print(type(10))
A) Float
B) Integer
C) String
D) List
Assessment 1:
Q3. What is the data type of print(type[10]))
A) Float
B) Integer
C) String
D) List
Assessment 1:
Q3. What is the data type of print(type[10]))
A) Float
B) Integer
C) String
D)List
Assessment 1:
Q4. What is the data type of print(type(“10”))
A) Float
B) Integer
C) String
D) List
Assessment 1:
Q4. What is the data type of print(type(“10”))
A) Float
B) Integer
C) String
D) List
Assessment 1:
Q5. What is the output of below code:
print(bool(0), bool(3.14159), bool(-3), bool(1.0+1j))
a) False True False True
b) True True False True
c) True True False False
d) False True True True
Assessment 1:
Q5. What is the output of below code:
print(bool(0), bool(3.14159), bool(-3), bool(1.0+1j))
a) False True False True
b) True True False True
c) True True False False
d) False True True True
Assessment 1:
Q6. What is the output of below code:
str1 = "PYnative"
print(str1[1:4], str1[:5], str1[4:], str1[0:-1], str1[:-1])
a) PYn Pynat ive Pynativ vitanYP
b) Yna PYnat tive PYnativ vitanYP
c) Yna PYnat tive PYnativ PYnativ
Assessment 1:
Q6. What is the output of below code:
str1 = "PYnative"
print(str1[1:4], str1[:5], str1[4:], str1[0:-1], str1[:-1])
a) PYn Pynat ive Pynativ vitanYP
b) Yna PYnat tive PYnativ vitanYP
c) Yna PYnat tive PYnativ PYnativ
Assessment 1:
Q7. What is the output of below code:
aList = ["PYnative", [4, 8, 12, 16]]
print(aList[0][1])
print(aList[1][3])
a) P8
Y 16
b) P
12
c) Y
16
Assessment 1:
Q7. What is the output of below code:
aList = ["PYnative", [4, 8, 12, 16]]
print(aList[0][1])
print(aList[1][3])
a) P8
Y 16
b) P
12
c) Y
16
Assessment 1:
Q8. What is the output of below code:
aList = [10, 20, 30, 40, 50, 60, 70, 80]
print(aList[2:5])
print(aList[:4])
print(aList[3:])
a) [20, 30, 40, 50]
[10, 20, 30, 40]
[30, 40, 50, 60, 70, 80]
b) [30, 40, 50]
[10, 20, 30, 40]
[40, 50, 60, 70, 80]
Assessment 1:
Q8. What is the output of below code:
aList = [10, 20, 30, 40, 50, 60, 70, 80]
print(aList[2:5])
print(aList[:4])
print(aList[3:])
a) [20, 30, 40, 50]
[10, 20, 30, 40]
[30, 40, 50, 60, 70, 80]
b) [30, 40, 50]
[10, 20, 30, 40]
[40, 50, 60, 70, 80]
Assessment 1:
Q9. What is the output of below code:
sampleList = [10, 20, 30, 40, 50]
[Link]()
print(sampleList)
[Link](2)
print(sampleList)
a) [20, 30, 40, 50]
[10, 20, 40]
b) [10, 20, 30, 40]
[10, 20, 30, 50]
c) [10, 20, 30, 40]
[10, 20, 40]
Assessment 1:
Q9. What is the output of below code:
sampleList = [10, 20, 30, 40, 50]
[Link]()
print(sampleList)
[Link](2)
print(sampleList)
a) [20, 30, 40, 50]
[10, 20, 40]
b) [10, 20, 30, 40]
[10, 20, 30, 50]
c) [10, 20, 30, 40]
[10, 20, 40]
Assessment 1:
Q10. Select the correct way to print Emma’s age:
student = {1: {'name': 'Emma', 'age': '27', 'sex': 'Female'}, 2: {'name':
'Mike', 'age': '22', 'sex': 'Male'}}
a) student[0][1]
b) student[1][“age”]
c) student[0][“age”]
Assessment 1:
Q10. Select the correct way to print Emma’s age:
student = {1: {'name': 'Emma', 'age': '27', 'sex': 'Female'}, 2: {'name':
'Mike', 'age': '22', 'sex': 'Male'}}
a) student[0][1]
b) student[1][“age”]
c) student[0][“age”]
Assessment 1:
Q11. Select true statements regarding the Python tuple
a) We can remove the item from tuple but we cannot update items of the
tuple
b) We cannot delete the tuple
c) We cannot remove the items from the tuple
d) We cannot update items of the tuple.
Assessment 1:
Q11. Select true statements regarding the Python tuple
a) We can remove the item from tuple but we cannot update items of the
tuple
b) We cannot delete the tuple
c) We cannot remove the items from the tuple
d) We cannot update items of the tuple.
Assessment 1:
Q12. Write a Python program to print the following string in same format:
Note: Check for quotes, new line and tabs.
Twinkle, twinkle, little star,
“How I wonder what you are! “
Up above the world so high,
‘Like a diamond in the sky’.
Assessment 1:
Q13. Write a Python program which accepts the radius of circle and compute the area.
Assessment 1:
Q14. Write a Python program which accepts the user name and print them in reverse order.
Example:
Name=“John”
Output should be “nhoJ”
Assessment 1:
Q15. Write a Python program to display the first and last colors from the following list.
color_list = ["Red","Green","White" ,"Black“]
Assessment 1:
Q16. Write a Python program to calculate the length of a string.
Quiz:
Q1. Given the nested if-else below, what will be the value x when the code executed successfully:
x=0
a=5
b=5
if a > 0:
if b < 0:
x=x+5
elif a > 5:
x=x+4
else: x = x + 3
else: x = x + 2
print(x)
a) 0
b) 4
c) 2
d) 3
Quiz:
Q1. Given the nested if-else below, what will be the value x when the code executed successfully:
x=0
a=5
b=5
if a > 0:
if b < 0:
x=x+5
elif a > 5:
x=x+4
else: x = x + 3
else: x = x + 2
print(x)
a) 0
b) 4
c) 2
d) 3
Quiz:
Q2. Given the nested if-else below, what will be the value x when the code executed successfully:
x=0
a=0
b=5
if a > 0:
if b < 0:
x=x+5
elif a > 5:
x=x+4
else: x = x + 3
else: x = x + 2
print(x)
a) 0
b) 4
c) 2
d) 3
Quiz:
Q2. Given the nested if-else below, what will be the value x when the code executed successfully:
x=0
a=0
b=5
if a > 0:
if b < 0:
x=x+5
elif a > 5:
x=x+4
else: x = x + 3
else: x = x + 2
print(x)
a) 0
b) 4
c) 2
d) 3
Quiz:
Q3. if -3: will evaluate to
a) True
b) False
Quiz:
Q3. if -3: will evaluate to
a) True
b) False
Quiz:
Q4. What is the value of x
x=0
while (x < 100):
x=x+2
print(x)
a) 101
b) 99
c) None of the above, this is an infinite loop
d) 100
Quiz:
Q4. What is the value of x
x=0
while (x < 100):
x=x+2
print(x)
a) 101
b) 99
c) None of the above, this is an infinite loop
d) 100
Quiz:
Q5. What is the output of the following if statement
a, b = 12, 5
if a + b:
print('True')
else:
print('False')
a) True
b) False
Quiz:
Q5. What is the output of the following if statement
a, b = 12, 5
if a + b:
print('True')
else:
print('False')
a) True
b) False
Loops:
FOR LOOP
For Loop:
A for loop is used for iterating over a sequence (that is
either a list, a tuple, a dictionary, a set, or a string).
With the for loop we can execute a set of statements, once
for each item in a list, tuple, set etc.