You are on page 1of 9

PYTHON PROGRAMMING QUESTIONS

1. What will be the output of the following code snippet?


count = 0
while(True):
if count % 3 == 0:
print(count, end = " ")
if(count > 15): break;
count += 1
Options
A. 0 1 2 ….15
B. Infinite Loop
C. 0 3 6 9 12 15
D. 0 3 9 12
2. What will be the output of the following code snippet?
a = [1, 2, 3, 4]
b = [3, 4, 5, 6]
c = [x for x in a if x not in b]
print(c)
Options:
A. [1,2]
B. [5,6]
C. [1,2,5,6]
D. [3,4]
3. What will be the output of the following code snippet?
set1 = {1, 3, 5}
set2 = {2, 4, 6}
print(len(set1 + set2))
Options:
A. 3
B. 6
C. 0
D. Error

4. What will be the value of the following Python expression?

4+3%5
a) 7
b) 2
c) 4
d) 1

5. The number as a multiple of 5


The lowest number 5
The highest number is 100 (Choose two.)

a. from random import randint


print(randint(0,20)*5)

b. from random import randint


print(randint(1,20)*5)

c. from random import randrange


print(randrange(0,100,5))
d. from random import randrange
print(randrange(5,105,5)

Options:
A. (a,b)
B. (b,d)
C. (a,c)
D. (c,d)

6. Which of the following statements is used to create an empty


set in Python?
Options:
a) ( )
b) [ ]
c) { }
d) set()

7. you writing the following code to determine a students final grade


based on their current grade(grade) and rank (rank)
grade = 76
rank = 3
if grade >80 and rank >=3:
grade += 10
elif grade >= 70 and rank > 3:
grade += 5
else:
grade -= 5
print(grade)
What value will print?
Options:
A. 71
B. 76
C. 82
D. 89

8. Write the output for program?

a = "config1"
print(a)
b=a
a+="config2"
print(a)
print(b)

9. You are writing a code to create an E shape from asterisk.

****
*
****
*
****

10. You are creating a Python program


that shows a congratulation message to
employees on their service
anniversary. You need to calculate the
number of years of service and print a
congratulatory message.
You have written the following code. Line numbers are included
for reference only.

You need to complete the program. Which code should you use at
line 03?

Options:
A. print("Congratulations on" + (int(end)-int(start)) + "years of
service!")
B. print("Congratulations on" + str(int(end)-int(start)) +"years of
service!")
C. print("Congratulations on" + int(end - start) + "years of
service!")
D. print("Congratulations on" + str(end - start)) + "years of
service!")int must be converted to string

11. Operation on the following sequence structure.


alph = “abcdefghijklmnopqrstuvwxyz”
Move the appropriate results from the List to the left to
the correct slicing operations on the rightyou may use
each results once, more thanonce, or not at all.
alph[3:15]……………………..
alph[:15]……………………….

Options:

A. defghilklmno
B. cdefghijklmn
C. abcedfghijklmno
D. cdefghijklmnopq
E. defghijklmnopqr
12. name = input()
What does the following statement do?
Options:
A. Allows a user to enter text in the console
B. Creates an HTML input element
C. Display a message box that allows user input
D. Displays all input device on the computer

13. You develop a python application for your company


You want to add notes to your code so other team
members will understand what should you do?
Options:
A. Place the notes after # on any line
B. Place the notes within /* and */ in any code segment
C. Place the notes < ! - -and - - > in any code segment
D. Place the notes after // on any line
14. A program that calculate a users approximate year of birth.
The program asks user for the user's age(age) and the current
year(year). Then outputs the users approximate year of birth in
a message.
You write the following code and answer the questions by
selecting the correct option from each drop-down list.
age = input(" enter youyr age: ")
year = input("enter the four digit year: ")
born = eval(year) - eval(age)
message = "you were born in " + str(born)
print(message)
Questions:
what data types in age in line 01?
what data types in born in line 03?
what data types in message in line 04?

15. You are developing a Python application for your company. You write
the following code:
Options:
True (or) False
A. What is displayed after the first print?
B. What is displayed after the second print?
C. What is displayed after the third print?
D. What is displayed after the fourth print?

16. value1=24
Value2=7
Value3=17.9
Answer=(value1%value2*100)//2.0**3.0-value2
Print (Answer)
Options:

A. The value 30.5 is displayed


B. Syntax error occurs
C. The value 457 is displayed
D. The value 30.0 is displayed
17. What will be the output of the following Python
function?
len(["hello",2, 4, 6])
Options:
a) Error
b) 6
c) 4
d) 3

18. What will be the output of the following Python code?

x = 'abcd'
for i in range(len(x)):
print(i)
Options:
a) error
b) 1 2 3 4
c) a b c d
d) 0 1 2 3

19. What will be the output of the following Python program?


def foo(x):
x[0] = ['def']
x[1] = ['abc']
return id(x)
q = ['abc', 'def']
print(id(q) == foo(q))
Options:
a) Error
b) None
c) False
d) True

20. To add a new element to a list we use which Python command?


Options:
a) list1.addEnd()
b) list1.addLast()
c) list1.append()
d) list1.add()

21. What will be the output of the following Python program?


def addItem(listParam):
listParam += [1]

mylist = [1, 2, 3, 4]
addItem(mylist)
print(len(mylist))
Options:
a) 5
b) 8
c) 2
d) 1

22. whats is recursion?


23. Write a Swap two variables without using the third variable in
Python?
24. Write a Add two number without + Operator in Python
25. You are writing a code Hollow square pattern
*****
* *
* *
* *
*****

You might also like