WorksheetsPython Basics
Total questions: 100
Worksheet time: 2hrs 27mins
If p=25 , what is p**2?
50
125
600
625
Who developed python?
Ritchie
Bill gates
Guido van Rossum
Sunder
Which character is used to denote long integer?
D
N
LO
L
In Python script editor, the errors will be shown in ----- color in the IDLE window?
green
black
red
orange
Which is known as simple assignment operator?
==
=
+=
#
Python uses ------ to define program blocks.
whitespace
delimiter
escape sequence
curly braces
Which function accepts all data as string or characters but not as numbers?
int()
output()
input()
print()
Which of these is not a core data type?
Lists
Dictionary
Tuples
Class
What is the output of the following code :
print 9//2
4.5
4.0
4
Error
Who developed the Python language?
Zim Den
Guido van Rossum
Niene Stom
Wick van Rossum
Which one of the following is the correct extension of the Python file?
.python
.p
.py
None of these
Which of the following declarations is incorrect?
_x = 2
__x = 3
__xyz__ = 5
None of these
Which of the following declarations is incorrect in python language?
xyzp = 5,000,000
x y z p = 5000 6000 7000 8000
x,y,z,p = 5000, 6000, 7000, 8000
x_y_z_p = 5,000,000
What will be the output of this statement?
>>>"a"+"bc"
a+bc
a bc
abc
a
print("3+4")
Which of these operators means EQUAL TO?
'='
'=>'
'<='
'=='
amount = 2 + 5 * 2
What is the output of range(1,10)
0123456789
123456789
1 to 10
012345
Choose the correct declaration of a float variable with the value 3.14
pi = "3.14"
pi = int(3.14)
pi = 3.14
float pi = 3.14
What is the final result of the expression 4 + 5 * 3?
27
12
19
21
What is the final result of the expression 7 / 3 + 6?
0
8.33333333
8
.777777777778
What does the following code print?
x = 3.4
y = 1
print int(x)
print x + y
3.4
4.4
3
4.4
3
4
The code causes an error
What is the final result of the expression 2**3?
6
8
2
That is not a valid Python expression.
What is the operator below called?
%
Exponent
Modulus
Divide
Percent
print(9//3,9/3)
3 3.3
3.3 3
3.0 3.3
3.3 3.3
Valid operation?
'2'-'1'
'third'*'2'
'sum'**3
"2"+"1"
What is the output of this expression, 3*1**3?
3
21
9
33
print(1.1+2.2==3.3)
True
False
Error
3.3
Suppose the following statements are executed:
a = 100 b = 200
What is the value of the expression a and b?
200
100
0
False
What is the output of “hello”+1+2+3 ?
hello123
hello
Error
hello6
str1 = "My salary is 7000"; str2 = "7000" print(str1.isdigit()) print(str2.isdigit())
False True
False False
True False
True True
print(-18//-2)
print(18//2)
print(18/2)
print(18%2)
print(str(18/2))
find output
9.0
9
9.0
0
9.0
9
9
9.0
0
"9.0"
9
9
9.0
0
9.0
9
9
9.0
0
90
x = 10
y = 50
if x ** 2 > 100 and y < 100:
print(x, y)
find output
NONE
Error
10,50
100
4 is 100 in binary and 11 is 1011. What is the output of the following bitwise operators?a = 4
b = 11
print(a | b)
print(a >> 2)
15
0
0
15
15
1
1
15
y = 10
x = y += 2
print(x)
12
10
0
Error
print(int(12.53))
print(round(12.53))
print(round(12.36,1))
13
12
12.4
12
13
12.4
12
13
12.3
error
Single line comment Symbol?
//
/
$
#
Choose the correct function to get the character from ASCII number
ascii(number)
char(number)
chr(number)
ord(number)
str1 = 'Welcome'
print (str1[:6] + ' PYnative')
Welcome PYnative
WelcomPYnative
Welcom PYnative
WelcomePYnative
The function pow(x,y,z) is evaluated as:
(x**y)**z
(x**y) / z
(x**y) % z
(x**y)*z
‘If’ is a decision making statement
TRUE
FALSE
What is the output?
more than 7
more than 23
spam
7
Which symbol means "not equal to"?
==
<=
>=
!=
If you want to test more than one condition (chained condition), what do you use after if statement?
elif
else
ifif
else if
Which character must be at the end of the line for if?
:
;
.
{
What does the = = symbol mean in Python?
Equal to or shows equality
Not Equal
Code that will be skipped
End of clause
What is the Python built-in function used to display numbers and text on the screen?
input
output
command
Failure
What will be the output of the code displayed?
(a)
What is the output from the following code?
(a)
What is the output from the following code?
(a)
What is the output from the following code?
(a)
What is the output of the following code?
(a)
What is the output from the following code?
(a)
What is the output from the following code?
(a)
What is the missing line of code?
new = chr(new)
new = ord(new)
new = chr(letter)
print new
What is the missing line of code?
if new > ord('z'):
If new =< ord('z'):
if new > chr('z'):
else next:
The following message was encoded using a Rotating Cipher (Ceaser shift).
transfer the amount on wednesday
and sent as...
ywfsxjw ymj ts bjisjxifd
What was the key used to encrypt the message?
(a)
AB
['ab', 'cd']
AB
CD
['ab', 'cd']
['ab', 'cd']
Error
['ab', 'cd','AB']
['ab', 'cd','AB' , 'CD']
['ab', 'cd']
Infinite Loop
SyntaxError
1 2
1 2 3
1
123
1 2 3
TypeError
1
2
3
1234
4321
Error
1 2 3 4
What is the output of the below program
for i in (1, 2, 3, 4)[::-1]:
print(i,end='')
1234
4321
Error
1 2 3 4
What is the output of the below program
for i in {1, 2, 3, 4}[::-1]:
print(i,end='')
1234
4321
Error
1 2 3 4
What is the output of the below program
my_string = "Python"
for i in my_string:
print(i, end =" ")
Python
P y t h o n
P
Error
What is the output of the below program
my_string = "Python"
while i in my_string:
print(i, end =" ")
Python
P y t h o n
P
Error
Error
0 1 2 3 0
0 1 2 0
0 1 2
Error
What is the output of the following?
my_string = 'geeksforgeeks'
for i in range(my_string):
print(i)
geeksforgeeks
None
Error
0 1 2 3 … 12
The program will loop indefinitely
The value of number will be printed exactly 1 time
The while loop will never get executed
The value of number will be printed exactly 5 times
12
9
7
8
4
0
7
16
Number: 10
Number: number
Number: 0
Number: 11
5 4 3 2 1
-4 -3 -2 -1 0
-5 -4 -3 -2 -1
This is an infinite loop, so nothing will be printed
var1 = -2, var2 = 0
var1 = 0, var2 = -2
var1 = 0, var2 = -1
This is an infinite loop, so nothing will be printed
How many asterisks will be printed when the following code executes?
for x in [0, 1, 2, 3]:
for y in [0, 1, 2, 3, 4]:
print('*')
0
4
5
20
This is an infinite loop, so nothing will be printed
n starts at 10 and is incremented by 1 each time through the loop, so it will always be positive.
answer starts at 1 and is incremented by n each time, so it will always be positive.
You cannot compare n to 0 in the while loop. You must compare it to another variable.
In the while loop body, we must set n to False, and this code does not do that.
Which type of loop can be used to perform the following iteration: You choose a positive integer at random and then print the numbers from 1 up to and including the selected integer.
a for-loop or a while-loop
only a for-loop
only a while-loop
Current Letter : P
Current Letter : t
Current Letter : h
Current Letter : o
x = 2; y = 5
x = 5; y = 2
x = 4; y = 3
x = 4; y = 2
The program has five iterations but does not print anything.
.
The loop will repeat forever and results in an infinite loop.
The program compiles and prints "1 2 3 4 5 Blastoff!" where each space is a new line.
The program compiles and prints "5 4 3 2 1 Blastoff!" where each space is a new line.
nothing prints
'Done!'
'#'
'>'
The for loop is not an “indefinite” loop because…
it loops through a known set of items so it runs through as many iterations as there are items in the set.
it loops until some condition becomes True.
it loops until some condition becomes False.
it loops until it reaches a "break" statement.
What is the final value of i when you execute this block of code?
8
10
9
7
How many times will the program go through the while statement if i = 1?
10
9
8
7
What is the output for this block of code on the 3rd pass on the for loop?
2: 4
2: 5
2: 3
2: 2
Will the value of n change when you execute this block of code?
Yes
No
Not sure
I need more information
How many unique outputs will this block of code generate?
15
25
50
75
Read carefully: when will you encounter an output of "2 : 2 : 2" if you run this block of code?
25th pass
17th pass
9th pass
2nd pass
Which among these numbers should you enter to get an angry reaction from the block of code?
12
16
18
21
When will this block of code stop executing?
If you give what it wants
If you give what it needs
If you tell your darkest secret
If you give it an odd number
What will be the reaction returned if you entered 754?
(人◕ω◕)
(`Д´)
(◕‿◕✿)
(✪‿✪)
After inputting '3058', the program said, (人◕ω◕) thank you!
What will the program show next?
continue
(nothing)
Give me an even number:
(人◕ω◕) thank you!
