-
Notifications
You must be signed in to change notification settings - Fork 4
/
cit_quiz.py
53 lines (41 loc) · 1.52 KB
/
cit_quiz.py
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
# You're making a calculator that should add multiple numbers taken from input and output the result. The number of inputs is variable and should stop when the user enters "stop"
def calculator():
add = 0
multiply = 1
while True:
num = input("Enter a number: ")
if num == "stop":
break
else:
add += int(num)
multiply *= int(num)
print("The sum is:", add)
print("The product is:", multiply)
calculator()
# The given outputs A B C D (each letter is separated by a space). Modify the code to output each letter on a separate line, resulting in the following output.
def letter_output():
for letter in "A B C D":
# ignore the space
if letter == " ":
continue
print(letter)
letter_output()
# You are given a program with two inputs: one as password and the second one as password repeat. "Complete" if password and repeat are equal, and output "wrong", if they are not.
def password_check():
pass_1 = input("Enter password: ")
pass_2 = input("Repeat password: ")
if pass_1 == pass_2:
print("Complete")
else:
print("Wrong")
password_check()
# Bonus Question:
# Create a file called answersheet.txt and write your quiz answers
# on that file.
def bonus_question():
with open("answersheet.txt", "w") as file:
questions = 21
for i in range(questions):
answer = input(f"Enter answer for question {i+1}: ")
file.write(answer + "\n")
bonus_question()