WorksheetsPre-Assessement | Python Essentials | FT Batch 3 | Paramesh G
Total questions: 50
Worksheet time: 30mins
What is output by the following? Assume the user enters 3 and 9
a = input("Enter a number: ")
b = input ("Enter a number: ")
print ("Values: " + a + b)
Values: 39
Values: 12
12
39
Consider the following code:
x = input ("What year is it?")
print(x)
The Value stored in x is:
a string
an int
stored in secondary memory
a program
else: is used
to give an extra condition
to provide an output when the other conditions are false
because it is required
if we do not use it, it gives error
What would the program display if you ran this code and entered 2 and then 3 when prompted?
The total is 5.
The total is 23.
The total is 6.
An error.
Consider the file "d://test.txt" with the contents as given below:
Hi there,
I am loving Python.
Python is Simple
Choose the correct output from the above code snippet from the given options:
Read String is : Hi there
Read String is : Hi there,
Syntax error
Hi there,
I am loving Python.
Python is simple.
Consider a list, fruits=["Mango", "Banana", "Guava", "Strawberry"]. Match the following:
a. fruits[-4:]
b. fruits[-2:]
c. fruits[-4:-1]
d. fruits[1:4]
Select the correct answer for a, b, c & d
['Banana', 'Guava', 'Strawberry']
['Mango', 'Banana', 'Guava', 'Strawberry']
['Mango', 'Banana']
['Mango', 'Banana', 'Guava']
['Guava', 'Banana', 'Mango']
What gets printed?
names = ['Amir', 'Barry', 'Chales', 'Dao']
print(names[-1][-1])
A
r
Amir
Dao
o
What gets printed from the above piece of code?
11
12
21
22
33
List a is defined as follows:
a = [1, 2, 3, 4, 5]
Select all of the following statements that remove the middle element 3 from a so that it equals [1, 2, 4, 5]:
a[2:2] = []
del a[2]
a[2] = []
a[2:3] = []
a.remove(3)
Which of the following are true of Python dictionaries:
Dictionaries can be nested to any depth.
Dictionaries are accessed by key.
All the keys in a dictionary must be of the same type.
Dictionaries are mutable.
A dictionary can contain any object type except another dictionary.
Which of the following is not a valid way to define this dictionary in Python:
d = dict([
('foo', 100),
('bar', 200),
('baz', 300)
])
d = {}
d['foo'] = 100
d['bar'] = 200
d['baz'] = 300
d = dict(foo=100, bar=200, baz=300)
d = {'foo': 100, 'bar': 200, 'baz': 300}
d = { ('foo', 100), ('bar', 200), ('baz', 300) }
You have the following dictionary definition:
d = {'foo': 100, 'bar': 200, 'baz': 300}
What method call will delete the entry whose value is 200?
delete d('bar')
d.pop("bar")
d.remove("bar")
None of the above
What would be the output of the following code snippet?
a_dict = {'color': 'blue', 'fruit': 'apple', 'pet': 'dog'}
d_items = a_dict.items()
print(d_items)
('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')
dict_items([('color'), ('fruit'), ('pet')])
[('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')]
dict_items([('color', 'blue'), ('fruit', 'apple'), ('pet', 'dog')])
Which of the following is the output of the below Python code?
var1 = lambda var: var * 2
ret = lambda var: var * 3
result = 2
result = var1(result)
result = ret(result)
result = var1(result)
print(result)
24
12
7
36
48
Which of the following is the output of the below Python code?
[Note: Python 2.7.5 and above]
mylist=['a', 'aa', 'aaa', 'b', 'bb', 'bbb']
print(mylist[int(-1/2)])
b
bbb
'bbb'
a
What is the correct syntax to output the type of a variable or object in Python?
print(typeof(x))
print(typeof x)
print(typeOf(x))
print(type(x))
Which of the following is the output of the instructions given below?
mylist=[1, 5, 9, int('0')]
print(sum(mylist))
16
5
1
15
Which of the following statements best describes the behavior of the random.shuffle(mylist) as being used in the below code fragment?
import random
mylist = [10, 20, 30]
random.shuffle(mylist)
print(mylist)
return a list where elements 10, 20 and 30 would be at random positions.
It'll not modify the list. This function is just a placeholder and yet to be implemented.
shuffle the elements of the list in-place.
shuffle the elements for the no. of times equal to the size of the list.
Which of these collections defines a SET?
{"apple", "banana", "cherry"}
{"name": "apple", "color": "green"}
("apple", "banana", "cherry")
["apple", "banana", "cherry"]
How do you start writing a for loop in Python?
for x in y:
for each x in y:
for x > y:
How do you create a variable with the floating number 2.8?
x=float(2.8)
x=2.8
both option are correct
Which one is NOT a legal variable name?
my_var
my-var
Myvar
-myvar
Full form of UI
User Interface
Underrated interface
Under indent
Upper Indent
What will be the value of the following Python expression?
4 + 3 % 5
7
2
4
1
What is the order of precedence in python?
Exponential, Parentheses, Multiplication, Division, Addition, Subtraction
Exponential, Parentheses, Division, Multiplication, Addition, Subtraction
Parentheses, Exponential, Multiplication, Division, Subtraction, Addition
Parentheses, Exponential, Multiplication, Division, Addition, Subtraction
Which of the following is an invalid statement?
abc = 1,000,000
a b c = 1000 2000 3000
a,b,c = 1000, 2000, 3000
a_b_c = 1,000,000
What is the ASCII value of 'm' ?
110
109
77
76
What is the result of the following condition if:
A = 30
B = 21
C = 71
B != A or C < A
True
False
What is the output from the following code?
(a)
The program above
prints all the odd numbers between 1 and 20
prints all even numbers between 1 and 20
print all the odd numbers between 1 and 21
prints all the even numbers between 1 and 21
What is the missing line of code?
if new > ord('z'):
If new =< ord('z'):
if new > chr('z'):
else next:
The program above prints the sum of
all odd numbers less than 100
all even numbers less than 100
all numbers less than 100
What is the output of the program above
10
15
18
17
16
fruit1="kiwi"
fruit2="strawberry"
print(len(fruit1))
print(len(fruit2))
kiwi and strawberry
4
10
4 10
410
The process of creating a function is as follows
1. Use the keyword def to declare the function
2. Follow with defining the function name
3. Add parameters to the function: they should be within the parentheses() of the function.
4. End this line with a colon after the parenthesis.
5. Indent and then add the statements that the functions should execute
6. Include a return statement if the function should output something. Without the return statement, your function will return an object - None
What is missing from this function?
return value statement
Variable
Function definition
Parameters
The parameters could be a
Variable
Literal
Expression
Function
Predict the output
stop
slow
go
slow
None
go
Select which is true for Python function
A Python function can return only a single value
A function can take an unlimited number of arguments
A Python function can return multiple values
Python function doesn’t return anything unless and until you add a return statement
Predict the output.
Note: end=' ' is a single space
('cls', 'XII') ('test', 'UT1')
'cls' 'test'
'XII' 'UT1'
{'cls': 'XII'} {'test': 'UT1'}
What will be the output of the following Python code?print("abc.DEF". capitalize())
Abc.def
abc.def
ABC.DEF
Abc.Def
Is this code valid in Python?
>>> m=6,7,8,9
>>> m
No, many values will unpack
Yes, 6 will be printed
Yes, (6,7,8,9) will be printed
Yes, [6,7,8,9] will be printed
What will be the output of the following Python expression if x=56.236?
print("%.2f"%x)
56.236
56.23
56.0000
56.24
Which type of Programming does Python support?
Object Oriented Programming
Structured Programming
Functional Programming
All of the above
Which of the following is true for variable names in Python?
underscore and ampersand are the only two special characters allowed
unlimited length
all private members must have leading and trailing underscores
none of these
