-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquiz Python.py
More file actions
69 lines (63 loc) · 2.48 KB
/
quiz Python.py
File metadata and controls
69 lines (63 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
score = 0
print("1. Which function is used to take input from the user in Python?")
print("a. input()")
print("b. scan()")
print("c. read()")
print("d. cin()")
answer = input("Enter your answer (a/b/c/d): ").lower()
if answer == "a":
print("Correct!")
score += 1
else:
print("Oops! Your answer is wrong. The correct answer is: a. input()")
print("Reason: Python uses input() to take input from the user. scan(), read(), and cin() are not Python functions.")
print("\n2. Which operator is used for floor division in Python?")
print("a. /")
print("b. //")
print("c. %")
print("d. **")
answer = input("Enter your answer (a/b/c/d): ").lower()
if answer == "b":
print("Correct!")
score += 1
else:
print("Oops! Your answer is wrong. The correct answer is: b. //")
print("Reason: // divides numbers and returns the integer part of the quotient. / gives float division, % gives remainder, ** is exponentiation.")
print("\n3. Which loop is used when the number of iterations is known?")
print("a. for loop")
print("b. while loop")
print("c. do-while loop")
print("d. if-else loop")
answer = input("Enter your answer (a/b/c/d): ").lower()
if answer == "a":
print("Correct!")
score += 1
else:
print("Oops! Your answer is wrong. The correct answer is: a. for loop")
print("Reason: For loops are used when the number of iterations is known. While loops run based on a condition, not a fixed number.")
print("\n4. Which symbol is used for exponentiation in Python?")
print("a. ^")
print("b. **")
print("c. %")
print("d. //")
answer = input("Enter your answer (a/b/c/d): ").lower()
if answer == "b":
print("Correct!")
score += 1
else:
print("Oops! Your answer is wrong. The correct answer is: b. **")
print("Reason: ** is used for raising numbers to a power. ^ is a bitwise XOR operator, % gives remainder, // is floor division.")
print("\n5. Which of the following can be used to print a pattern in Python?")
print("a. loops")
print("b. functions")
print("c. lists")
print("d. dictionaries")
answer = input("Enter your answer (a/b/c/d): ").lower()
if answer == "a":
print("Correct!")
score += 1
else:
print("Oops! Your answer is wrong. The correct answer is: a. loops")
print("Reason: Loops allow repeating statements, which is essential for creating patterns. Functions, lists, and dictionaries alone cannot print patterns.")
print("\nQuiz Completed!")
print("Your score is:", score, "out of 5")