Python Questions

0 votes, 0 avg
606

Python Questions

1 / 15

1. What will be the output of the following program?

i = 0  
while i < 5:  
    print(i)  
    i += 1  
    if i == 3:  
        break  
else:  
    print(0)  

2 / 15

2. Which function is called when the following Python program is executed?

f = foo()
format(f)

3 / 15

3. Which of the following blocks will always be executed whether an exception is encountered or not in a program?

4 / 15

4. What happens if the file is not found in the following Python code?

a=False
while not a:
    try:
        f_n = input("Enter file name")
        i_f = open(f_n, 'r')
    except:
        print("Input file not found")

5 / 15

5. What is called when a function is defined inside a class?

6 / 15

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

    def C2F(c):

        return c * 9/5 + 32

    print C2F(100)

    print C2F(0)

7 / 15

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

def thrive(n):
 if n % 15 == 0:
   print("thrive", end = “ ”)
 elif n % 3 != 0 and n % 5 != 0:
   print("neither", end = “ ”)
 elif n % 3 == 0:
   print("three", end = “ ”)
 elif n % 5 == 0:
   print("five", end = “ ”)
thrive(35)
thrive(56)
thrive(15)
thrive(39)

8 / 15

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

a = [1, 2, 3]
a = tuple(a)
a[0] = 2
print(a)

9 / 15

9. Which of the following expressions can be used to multiply a given number ‘a’ by 4?

10 / 15

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

l=list('HELLO')
p=l[0], l[-1], l[1:3]
'a={0}, b={1}, c={2}'.format(*p)

11 / 15

11. What will be the datatype of the var in the below code snippet?

var = 10
print(type(var))
var = "Hello"
print(type(var))

12 / 15

12. Which of the following is false regarding conditional statement in Python?

13 / 15

13. Set makes use of __________
Dictionary makes use of ____________

14 / 15

14. Which of the following is not a valid set operation in python?

15 / 15

15. In Python, the break and continue statements, together are called ___ statement.

Your score is

The average score is 37%

0%

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.