WorksheetsPython Programming | Dayita
Total questions: 50
Worksheet time: 31mins
What does the following code do? myAge = int (myAge)
Converts the var (variable) myAge to a string
Converts the var (variable) myAge to a integer
Converts the var (variable) myAge from a integer to a string
Converts the var (variable) myAge to if statement
print("Hello world!" * 2)
Python is ___________ level programming language and is ___________.
High, compiled
High, interpreted
Low, compiled
Low, interpreted
A string
carries out an action
the elements of a command
a collection of characters
how elements in a commad are arranged
what does this code display:
counter = 1
while counter <4:
print (counter)
counter = counter + 1
1 2 3 4
1 2 3
0 1 2 3
0 1 2 3 4
Which of these codes is the correct syntax?
Print ("Hello World")
print ("Hello World")
PRINT ("Hello World")
print "Hello World"
What is the output of the following code?
def calculate (num1, num2):
answer = num1 * num2
print(answer)
calculate(2, 5)
11
7
10
answer
What will be the output of this code? x = [1, 2, 3] print(len(x))
3
2
1
Error
What would be the value of ‘new_score’ after running this code:
score = 44
total = 1
new_score = score * 2
88
44
45
22
What is the output of the following code? x = 5 print(x * 2)
10
5
25
Error
What will be the output of print("hello" + 1 + 2 + 3)?
Error
hello123
hello6
"hello"123
Which of the following checks if x is not equal to y?
if x not = y:
if x == y:
if x =! y:
if x != y:
Code to check if the variable x is less than 20.
if x <> 20:
if x <= 20:
if x <= 20
if x < 20:
Which operator performs exponentiation?
**
*
%
/
Takes the square root of x and returns a float.
math.random(x)
import.math(x)
sqrt.math(x)
math.sqrt(x)
guess=input()
guess=input()
guess=input()
guess=input()
teams = [“Man Utd”,“Man City”,"Arsenal"]
teams.append(“Liverpool”)
marks = 20
total = 5
newmarks = marks * 3
days = 5
if days > 6:
print(“Month”)
else:
print(“Week”)
Which has integer data type?
Phone number
Zip code
HN
Number of students in the class
There are 40 students in a classroom. We would like to get all students whose name starts with "A". Which looping is suitable?
For loop
While loop
You are in the car with traffic jammed at a junction. To cross that junction according to the traffic rules, which one is NOT applicable
While loop
Conditional Statement
For loop
print(3*4+5)
name = 'Dave'
greeting = "Good morning" + name
print (greeting)
Anil is writing a "rock, scissors, paper" program. He wants the game to repeat until the user doesn't want to play anymore. What loop should he use?
a FOR loop
a WHILE loop
i i i i i i
a a a a a a
a a a a a
None
Working
Stopped
Error
None
What will be the output of the following code?
A. 2
B. 4
C. 8
D. 16
What will be the output of the following code?
A. Inner
B. Outer
C. Error
D. None
What will be the output?
S=50.6
number=int(S)
new_number=number-1
print(new_number)
49.6
49
50
51.6
52
What output will this code produce?
Colours=[]
Colours.append(“blue”)
Colours.append(“green”)
Colours.append(“red”)
Print(colours[2])
blue
green
red
error
none of these
Why are local variable names beginning with an underscore discouraged?
they are used to indicate a private variables of a class
they confuse the interpreter
they are used to indicate global variables
they slow down execution
Which of the following statements create a dictionary?
d = {}
d = {"brand": "Tesla","electric": True}
d = {2012:"Model S", 2016:"Model 3"}
d = {"brand": "Tesla","electric": True,"colors": ["red", "white", "blue"]}
All of the mentioned
What is the output of the following lines
list = [[1, 3]]
list = list * 2
list[0][0] = 10
print(list)
[[1, 3], [1, 3]]
[[10, 3], [1, 3]]
[[1, 10], [1, 3]]
[[10, 3], [10, 3]]
people = ["John", "Rob", "Bob"]
print (people[-1])
what would this result be?
What will be the output of the following Python code?
a={1:"A",2:"B",3:"C"}
a.items()
items()
dict_items([(1,2,3)])
dict_items([(‘A’), (‘B’), (‘C’)])
dict_items([(1, ‘A’), (2, ‘B’), (3, ‘C’)])
What is the output of the given below program?
print("Know Program".split())
‘Know’, ‘Program’
(‘Know’, ‘Program’)
[‘Know’, ‘Program’]
{‘Know’, ‘Program’}
Suppose a function called add() is defined in a module called adder.py. Which of the following code snippets correctly show how to import and use the add() function? Select all that apply.
from adder import add
result = adder.add(2, 3)
from adder import add
result = add(2, 3)
import add from adder
result = add(2, 3)
import adder
result = adder.add(2, 3)
Find the output of the following program segments:
for i in range(20,30,2):
print(i)
20 22 24 26 28
20
22
24
26
28
20 22 24 26 28 30
20
22
24
26
28
30
Which one of the following if statements will not execute successfully?
1) if (1, 2);
print(‘foo’)
2) if (1, 2):
print(‘foo’)
3) if (1):
print( ‘foo’ )
4) if (1);
print( ‘foo’ )
1,4
2
2,4
4
Predict the output of the following code:
x=3
If x>2 or x<5 and x==6:
Print(“ok”)
else:
print(“no output”)
ok
okok
no output
none of above
Who is the founder of Python Programming Language?
Rasmus Ganilo
Dennis Ritchie
Guido van Rossum
James Gosling
File extension of Python program is ______
.py
.p
.pyx
.pyy
List index begins with _________.
0
1
-1
-2
