Skip to content

Commit 15af477

Browse files
authored
Add files via upload
1 parent d5a290e commit 15af477

File tree

3 files changed

+177
-0
lines changed

3 files changed

+177
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Simple quiz that asks questions, and display results
2+
3+
4+
quiz = {
5+
'questions 1':{
6+
'question': 'What is the capital of France?: ',
7+
'answer': 'Paris'
8+
},
9+
'questions 2':{
10+
'question': 'What is the capital of Germany?: ',
11+
'answer': 'Berlin'
12+
},
13+
'questions 3':{
14+
'question': 'What is the capital of Canada?: ',
15+
'answer': 'Toronto'
16+
},
17+
'questions 4':{
18+
'question': 'What is the capital of Italy?: ',
19+
'answer': 'Rome'
20+
},
21+
'questions 5':{
22+
'question': 'What is the capital of Spain?: ',
23+
'answer': 'Madrid'
24+
},
25+
'questions 6':{
26+
'question': 'What is the capital of Portugal?: ',
27+
'answer': 'Lisbon'
28+
},
29+
'questions 7':{
30+
'question': 'What is the capital of Switzerland?: ',
31+
'answer': 'Bern'
32+
},
33+
'questions 8':{
34+
'question': 'What is the capital of Netherland?: ',
35+
'answer': 'Amsterdam'
36+
},'questions 9':{
37+
'question': 'What is the capital of Austra?: ',
38+
'answer': 'Vienna'
39+
},'questions 10':{
40+
'question': 'What is the capital of Russia?: ',
41+
'answer': 'Moscow'
42+
}
43+
}
44+
45+
46+
score = 0
47+
48+
def display_Quiz(quiz, score):
49+
for key, value in quiz.items():
50+
print(value['question'])
51+
user_answer = None
52+
53+
user_answer = input('Your answer: ').lower()
54+
55+
if user_answer == value['answer'].lower():
56+
print('Correct!😁')
57+
score += 1
58+
print(f'Your Score = {score}👌')
59+
60+
else:
61+
print('Wrong!😢')
62+
print(f'Correct Answer = {value['answer']}')
63+
print(f'Your Score = {score}👌')
64+
65+
print(f'Total = {score} / 10')
66+
percentage = (score / 10) * 100
67+
print(f'Percentage = {percentage}%')
68+
print(f'\n Thanks for participating...😁❤️')
69+
70+
71+
display_Quiz(quiz, score)
72+
73+
74+
75+
76+
77+
78+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
def binary_search(list, element):
2+
midpoint = 0
3+
start = 0
4+
end = len(list)
5+
steps = 0
6+
7+
while start <= end:
8+
print(f'Steps {steps}: {list[start:end+1]}')
9+
10+
steps +=1
11+
12+
midpoint = (start + end) // 2
13+
14+
if element == list[midpoint]:
15+
return midpoint
16+
elif element < list[midpoint]:
17+
end = midpoint - 1
18+
else:
19+
start = midpoint +1
20+
21+
if element in list:
22+
print("Target found: ",True)
23+
else:
24+
print("Target not found: ",False)
25+
26+
return -1
27+
28+
def main():
29+
my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,]
30+
target = int(input('Enter a target: '))
31+
32+
binary_search(my_list, target)
33+
34+
main()
35+
36+
37+
38+
39+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# A simple calculator program
2+
def Menu(): # Menu to hold menu options and user choices
3+
menu_options = (1,2,3,4,5)
4+
5+
user_choice = None
6+
7+
print("\n Menu \n 1. Addition 2. Subtraction 3. Multiplication 4. Division 5 Exit.")
8+
9+
while True:
10+
# Repeat the loop till user option is true.
11+
try:
12+
user_choice = int(input('Enter a choice from the menu (1-5): '))
13+
if user_choice not in menu_options:
14+
print("Invalid input")
15+
continue
16+
17+
except ValueError:
18+
print("Please enter a valid choice")
19+
continue
20+
21+
return user_choice
22+
23+
24+
def get_user_values(): # A function to store user values for calculators
25+
num1 = int(input('Enter first number: '))
26+
num2 = int(input('Enter second number: '))
27+
return num1, num2
28+
29+
def Calculate(user_choice, num1, num2): # A function that calculates base on user values and menu choices
30+
31+
if user_choice == 1:
32+
return f'{num1} + {num2} = {num1 + num2}'
33+
34+
elif user_choice == 2:
35+
return f'{num1} - {num2} = {num1-num2}'
36+
37+
elif user_choice == 3:
38+
return f'{num1} x {num2} = {num1*num2}'
39+
40+
elif user_choice == 4:
41+
if num2 == 0:
42+
print("Division by zero is invalid")
43+
else:
44+
return f'{num1} ÷ {num2} = {num1/num2}'
45+
46+
def Main(): # A main function to run and test the program
47+
while True:
48+
user_choice = Menu()
49+
50+
if user_choice == 5:
51+
print('Thanks for using this program...😁')
52+
break
53+
54+
num1, num2 = get_user_values()
55+
56+
result = Calculate(user_choice, num1, num2)
57+
58+
print(result)
59+
60+
Main() # CAll the Main function to run the program

0 commit comments

Comments
 (0)