➤ How to Code a Game
➤ Array Programs in Java
➤ Java Inline Thread Creation
➤ Java Custom Exception
➤ Hibernate vs JDBC
➤ Object Relational Mapping
➤ Check Oracle DB Size
➤ Check Oracle DB Version
➤ Generation of Computers
➤ XML Pros & Cons
➤ Git Analytics & Its Uses
➤ Top Skills for Cloud Professional
➤ How to Hire Best Candidates
➤ Scrum Master Roles & Work
➤ CyberSecurity in Python
➤ Protect from Cyber-Attack
➤ Solve App Development Challenges
➤ Top Chrome Extensions for Twitch Users
➤ Mistakes That Can Ruin Your Test Metric Program
Q1) Can we write if/else into one line in python?
a) Yes
b) No
c) if/else not used in python
d) None of the above
View Answer
Answer:- a) YesExplanation: We can write if/else in one line. For eg i = 2 if a > 5 else 0.
Q2) Which one of the following is a valid Python if statement.
a) if a>=2 :
b) if (a >= 2)
c) if (a => 22)
d) if a >= 22
View Answer
Answer:- a) if a>=2 :Explanation:- If statement always end with colon (:)
Q3) What keyword would you use to add an alternative condition to an if statement?
a) else if
b) elseif
c) elif
d) None of the above
View Answer
Answer:- c) elifQ4) What is the output of the given below program?
if 1 + 3 == 7:
print("Hello")
else:
print("Know Program")
a) Hello
b) Know Program
c) Compiled Successfully, No Output.
d) Error
View Answer
Answer:- b) Know ProgramThe 1+3 = 4 which is not equal to 7 therefore else block will be executed.
Q5) What is the output of the given below program?
if 3 + 4 == 7:
print("Hi")
else:
print("Know Program")
print("Hello")
a) Hi
b) Know Program
c)
Hi
Hello
d)
Know Program
Hello
View Answer
Answer:- c)Hi
Hello
The 3+4 = 7 is equal to 7 therefore if block will be executed. The remaining statement after if-else block also will be executed.
Q6) Find the output of the given Python program?
a = 25
if a < 15:
print("Hi")
if a <= 30:
print("Hello")
else:
print("Know Program")
a) Hi
b) Hello
c) Know Program
d) Compiled Successfully, No Output.
View Answer
Answer:- b) HelloHere 25 < 15 => false; therefore the if-block will not be executed. Next, 25 <= 30, condition becomes true therefore if-block will be executed.
Q7) What is the output of the given below program?
a = 25
if a > 15:
print("Hi")
if a <= 30:
print("Hello")
else:
print("Know Program")
a) Hi
b) Hello
c)
Hi
Hello
d) Hi
Know Program
e) Hello
Know Program
View Answer
Answer:- c)Hi
Hello
Here 25 > 15, condition is true therefore first if-statment will be executed. Next, 25 <= 30, condition is true therefore second if-statement also will be executed.
Q8) Find the output of the given Python program?
a, b, c = 1, 3, 5
if a > 0:
if b < 2:
print("Hi")
elif c > 3:
print("Hello")
else:
print("Know Program")
a) Hi
b) Hello
c) Know Program
d) Compiled Successfully, No Output.
View Answer
Answer:- b) HelloQ9) Find the output of the given Python program?
a, b, c = 1, 3, 5
if a + b + c:
print("Hello")
else:
print("Know Program")
a) Hello
b) Know Program
c) Compiled Successfully, No Output.
d) Error
View Answer
Answer:- a) HelloQ10) What is the output of the given below program?
if a < b:
print("Hello")
else:
print("Know Program")
a) Hello
b) Know Program
c) Compiled Successfully, No Output.
d) Error
View Answer
Answer:- d) ErrorThe variables are not assigned with any value.
Q11) What is the output of the given below program?
a = b = true
if (a and b):
print("Hello")
else:
print("Know Program")
a) Hello
b) Know Program
c) Compiled Successfully, No Output.
d) Error
View Answer
Answer:- d) ErrorAlso See:- Python Pandas MCQ
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!