Python Coding Practice - 2 (16 - 30 Questions)

Q16. What is Python primarily considered?
Think readability, dynamic typing, and interpreted execution.
Answer: A high-level, interpreted programming language
Explanation: Python is high-level, interpreted, dynamically typed, and emphasizes readability.
Q17. One key reason Python is popular is its ____.
(single word)
PEP 8 and indentation contribute to this.
Answer: readability
Explanation: Python’s clear syntax and conventions make code easier to read and maintain.
Q18. Select all common Python use-cases.
Think Django, Pandas, and automation scripts.
Answer: Data analysis, Web development, Machine learning / AI
Explanation: Python is widely used for web, data, AI, and automation; low-level firmware isn’t typical.
Q19. Write the standard first Python program message.
print("")
Include comma and exclamation as commonly used.
Answer: Hello, World!
Explanation: The canonical first program prints “Hello, World!” via the print() function.
Q20. Fill in: Python single-line comments start with ____.
It’s one character.
Answer: #
Explanation: The hash/pound character introduces single-line comments.
Q21. Which variable name is valid in Python?
Start with letter/underscore, no hyphens, avoid keywords.
Answer: user_name2
Explanation: Names can include letters, digits, underscores; cannot start with a digit or use keywords.
Q22. type(3.0) returns which type?
Think decimal numbers.
Answer: <class 'float'>
Explanation: 3.0 is a float; type() shows the class name.
Q23. Convert string "42" to an integer.
num = ("42")
Use a built-in conversion function.
Answer: int
Explanation: int("42") converts the numeric string to an integer type.
Q24. Format output with f-string to show name and age.
name="A"; age=20
print()
Use f-strings with braces to embed variables.
Answer: f"Name: {name}, Age: {age}"
Explanation: f-strings allow inline variable interpolation.
Q25. Complete the if-elif-else structure to classify score.
score = 85
if score >= 90:
  print("A")
elif score >= 80:
  print()
else:
  print("C")
Use quotes for a string literal.
Answer: "B"
Explanation: With 85, the elif branch prints "B".
Q26. Fill in to check adult with valid ID.
age = 20; has_id = True
if age >= 18 has_id:
  print("Allowed")
Combine two conditions.
Answer: and
Explanation: Both conditions must be true to allow entry.
Q27. Use range() to print numbers 0 to 4.
for i in :
  print(i)
range(stop) goes from 0 to stop-1.
Answer: range(5)
Explanation: Iterates 0,1,2,3,4.
Q28. Insert the control statement to stop at 3.
for i in range(10):
  if i == 3:
    
  print(i)
Stops the loop immediately.
Answer: break
Explanation: break exits the loop when condition is met.
Q29. Which prints a left-aligned triangle of stars (3 rows)?
for r in range(1, 4):
  print( ? )
Use string multiplication with the row number.
Answer: "*" * r
Explanation: Repeats "*" r times, producing 1,2,3 stars per row.
Q30. Fill in to check if s is a palindrome.
s = "level"
print(s == s[])
Reverse the string using slicing.
Answer: ::-1
Explanation: s[::-1] reverses the string; equality means it’s a palindrome.

Post a Comment

0 Comments