SDT Ass Day 1
SDT Ass Day 1
1 MARKS:
10. You want to calculate the sum of numbers from 1 to 10. Which of the following is
correct?
A. sum = range(1, 10)
B. sum = 0; for i in range(1, 11): sum += i
C. sum = 0; while i < 10: sum = sum + i
D. sum = sum(1, 10)
11. Which of the following code snippets finds whether a number is prime?
A.python
Copy
Edit
for i in range(2, num):
if num % i == 0:
print("Not Prime")
break
else:
print("Prime")
B. if num % 2 == 0: print("Prime") else: print("Not Prime")
C. print("Prime")
D. while num != 0: print("Not Prime")
12. In a number guessing game, which function is used to get user input in Python 3?
A. raw_input()
B. scan()
C. input()
D. get()
13. Which loop is most suitable for a menu-driven calculator until the user chooses exit?
A. for loop
B. while loop
C. do-while
D. foreach
14. How can you repeat a pattern like the following using a loop?
Markdown
*
*
**
A. Nested for loop
B. Single while loop
C. Recursion
D. Loop with break
15. Which of these mini-projects best applies conditionals and loops together?
A. Image Editor
B. Prime number generator
C. Snake Game
D. Alarm Clock