Skip to content

Commit b0b774f

Browse files
authored
Merge pull request #14 from Mmabiaa/content-branch
Uploaded Easy Level Directory
2 parents 40d06a6 + 7fff19e commit b0b774f

File tree

6 files changed

+443
-0
lines changed

6 files changed

+443
-0
lines changed
+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Simple quiz that asks questions, and display results
2+
3+
4+
def Quiz_Question(): # A function that stores quiz questions and answers and return quiz and score
5+
6+
score = 0
7+
8+
quiz = {# A dictionary containing quiz questions and answers
9+
'questions 1':{
10+
'question': 'What is the capital of France?: ',
11+
'answer': 'Paris'
12+
},
13+
'questions 2':{
14+
'question': 'What is the capital of Germany?: ',
15+
'answer': 'Berlin'
16+
},
17+
'questions 3':{
18+
'question': 'What is the capital of Canada?: ',
19+
'answer': 'Toronto'
20+
},
21+
'questions 4':{
22+
'question': 'What is the capital of Italy?: ',
23+
'answer': 'Rome'
24+
},
25+
'questions 5':{
26+
'question': 'What is the capital of Spain?: ',
27+
'answer': 'Madrid'
28+
},
29+
'questions 6':{
30+
'question': 'What is the capital of Portugal?: ',
31+
'answer': 'Lisbon'
32+
},
33+
'questions 7':{
34+
'question': 'What is the capital of Switzerland?: ',
35+
'answer': 'Bern'
36+
},
37+
'questions 8':{
38+
'question': 'What is the capital of Netherland?: ',
39+
'answer': 'Amsterdam'
40+
},'questions 9':{
41+
'question': 'What is the capital of Austra?: ',
42+
'answer': 'Vienna'
43+
},'questions 10':{
44+
'question': 'What is the capital of Russia?: ',
45+
'answer': 'Moscow'
46+
}
47+
}
48+
return score, quiz
49+
50+
51+
52+
53+
def display_Quiz(quiz, score): # A function that displays quiz and results
54+
55+
for key, value in quiz.items(): # A loop to iterate through the quiz items and display (questions and answers)
56+
print(value['question']) # Printing each question in the quiz
57+
user_answer = None
58+
59+
user_answer = input('Your answer: ').lower()
60+
61+
# conditions to validate results
62+
if user_answer == value['answer'].lower():
63+
print('Correct!😁')
64+
score += 1
65+
print(f'Your Score = {score}👌')
66+
print(' ')
67+
68+
else:
69+
print('Wrong!😢')
70+
print(f'Correct Answer = {value['answer']}')
71+
print(f'Your Score = {score}👌')
72+
print(' ')
73+
74+
print(f'\n Total = {score} / 10')
75+
percentage = (score / 10) * 100
76+
print(f'Percentage = {percentage}%')
77+
print(f'\n Thanks for participating...😁❤️')
78+
79+
80+
def main(): # main function to run the program.
81+
score, quiz = Quiz_Question()
82+
83+
display_Quiz(quiz, score)
84+
85+
main() # calling the main function to run the program.
86+
87+
88+
89+
90+
91+
92+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
import random # A library to generate random choices
3+
4+
# variables to store options
5+
ROCK = 'r'
6+
SCISSORS = 's'
7+
PAPER = 'p'
8+
9+
emojis = {ROCK:'🪨', PAPER:'📃', SCISSORS:'✂️'} # A dictionary to store option keys with emoji values
10+
options = tuple(emojis.keys()) # A tuple to store option values
11+
12+
13+
14+
def get_user_choice():# A function to return a user choice
15+
16+
user_input = input("Rock, paper, or scissors? (r/p/s): ")
17+
18+
if user_input in options:
19+
return user_input
20+
else:
21+
print("Invalid input")
22+
23+
24+
25+
def display_choices(cpu, user_input): # A function that displays the choices (cpu, user_input)
26+
27+
print(f"You chose {emojis[user_input]}")
28+
print(f"Computer chose {emojis[cpu]}")
29+
30+
31+
def determine_winner(cpu, user_input): # A function that determines the winner
32+
33+
if ((user_input == ROCK and cpu == SCISSORS) or
34+
(user_input == SCISSORS and cpu == PAPER) or
35+
(user_input == PAPER and cpu == ROCK)):
36+
print("You won!🥳")
37+
elif(user_input == cpu):
38+
print("You tie!😎")
39+
else:
40+
print("You lose!😢")
41+
42+
43+
def Game():# A function to return various functions to start the game.
44+
while True:
45+
user_input = get_user_choice()
46+
47+
cpu = random.choice(options)
48+
49+
display_choices(cpu, user_input)
50+
51+
determine_winner(cpu, user_input)
52+
53+
Continue = input("Do you want to continue (y/n)😊: ").lower()
54+
55+
if Continue == 'n':
56+
print("Thanks for playing!😁")
57+
break
58+
59+
# Calling the Game function to initialize the program.
60+
Game()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# A simple number guessing game using python.
2+
import random # For random numbers
3+
4+
def number_guessing():
5+
number = random.randint(1,100)
6+
while True:
7+
8+
try:
9+
guess = int(input("Guess a number from 1 to 100: "))
10+
11+
if number == guess:
12+
print("Congratulations! You guessed the number!")
13+
break
14+
elif number > guess:
15+
print("Too low!")
16+
else:
17+
print("Too high!")
18+
19+
20+
except ValueError:
21+
print("Enter a valid number")
22+
23+
number_guessing()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# A simple program that helps users to get a password idea.
2+
import random
3+
import string
4+
5+
def Storage():
6+
characters = list(string.ascii_letters + string.digits + '!@#$%^&*()')
7+
8+
options = ['y', 'n']
9+
10+
return characters, options
11+
12+
def get_password(characters, options):
13+
14+
while True:
15+
user_choice = input('Do you want to generate a new password (y/n): ').lower()
16+
17+
if user_choice not in options:
18+
print('Enter a valid choice (y/n)')
19+
20+
21+
else:
22+
if user_choice == 'y':
23+
password_length = int(input('Enter password length: '))
24+
random.shuffle(characters)
25+
26+
password = []
27+
28+
for x in range(password_length):
29+
password.append(random.choice(characters))
30+
31+
random.shuffle(password)
32+
33+
password = ''.join(password)
34+
35+
print(password)
36+
37+
else:
38+
print('Thanks for using this program...😁')
39+
break
40+
41+
def Main():
42+
characters, options = Storage()
43+
44+
get_password(characters, options)
45+
46+
Main()
47+
48+
+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import random
2+
3+
# Constant variables
4+
MAX_LINE = 3
5+
MAX_BET = 100
6+
MIN_BET = 1
7+
8+
ROWS = 3
9+
COLS = 3
10+
11+
symbols_count = {
12+
'A':2,
13+
'B':4,
14+
'C':6,
15+
'D':8
16+
}
17+
18+
symbols_values = {
19+
'A':5,
20+
'B':3,
21+
'C':4,
22+
'D':2
23+
}
24+
25+
26+
def check_winnings(columns, lines, bet, values):
27+
winnings = 0
28+
lines_won = []
29+
for line in range(lines):
30+
symbol = columns[0][line]
31+
for column in columns:
32+
symbol_to_check = column[line]
33+
if symbol != symbol_to_check:
34+
break
35+
else:
36+
winnings += values[symbol] * bet
37+
lines_won.append(line + 1)
38+
39+
return winnings, lines_won
40+
41+
42+
43+
44+
def get_slot_machine_spin(rows, cols, symbols):
45+
all_symbols = []
46+
for symbol, symbols_count in symbols.items():
47+
for _ in range(symbols_count):
48+
all_symbols.append(symbol)
49+
50+
columns = []
51+
for _ in range(cols):
52+
column = []
53+
current_symbols = all_symbols[:]
54+
for _ in range(rows):
55+
value = random.choice(current_symbols)
56+
current_symbols.remove(value)
57+
column.append(value)
58+
columns.append(column)
59+
60+
return columns
61+
62+
def print_slot(columns):
63+
for row in range(len(columns[0])):
64+
for i, column in enumerate(columns):
65+
if i != len(columns)-1:
66+
print(column[row],end=' | ')
67+
else:
68+
print(column[row], end='')
69+
print()
70+
71+
72+
73+
74+
def deposit():
75+
while True:
76+
amount = input('How much would you like to deposit: $')
77+
if amount.isdigit():
78+
amount = float(amount)
79+
if amount > 0:
80+
break
81+
else:
82+
print('Amount must be greater than zero!')
83+
else:
84+
print('Please enter a number!')
85+
print('----------------------------------------------------------------')
86+
87+
return amount
88+
89+
def get_number_of_lines():
90+
while True:
91+
lines = input('Enter the number of lines to bet on(1-' + str(MAX_LINE) + '): ')
92+
if lines.isdigit():
93+
lines = int(lines)
94+
if 0 < lines <= MAX_LINE:
95+
break
96+
else:
97+
print('Enter a valid number of lines!')
98+
else:
99+
print('Please enter a number!')
100+
print('----------------------------------------------------------------')
101+
102+
return lines
103+
104+
def get_bet():
105+
while True:
106+
amount = input('How much would you like to bet: $')
107+
if amount.isdigit():
108+
amount = float(amount)
109+
if MIN_BET <= amount <= MAX_BET:
110+
break
111+
else:
112+
print(f'Betting amount must be between ${MIN_BET} - ${MAX_BET} !')
113+
else:
114+
print('Please enter a number!')
115+
116+
print('----------------------------------------------------------------')
117+
118+
return amount
119+
120+
def spin(balance):
121+
lines = get_number_of_lines()
122+
while True:
123+
bet = get_bet()
124+
total_bet = bet * lines
125+
126+
if total_bet > balance:
127+
print('You do not have enough balance to bet!')
128+
print(f'Current balance: ${balance}')
129+
print('----------------------------------------------------------------')
130+
else:
131+
break
132+
133+
print(f'You are betting ${bet} on ${lines} lines.\n Total bet: ${total_bet}')
134+
print('----------------------------------------------------------------')
135+
136+
slots = get_slot_machine_spin(ROWS, COLS, symbols_count)
137+
print_slot(slots)
138+
winnings, lines_won = check_winnings(slots, lines, bet, symbols_values)
139+
print('----------------------------------------------------------------')
140+
print(f'You won ${winnings}. ')
141+
print(f'You won on lines:', *lines_won)
142+
print('----------------------------------------------------------------')
143+
return winnings - total_bet
144+
145+
def main():
146+
balance = deposit()
147+
while True:
148+
print(f'Current balance: ${balance}')
149+
answer = input('Press enter to play (q to quit): ')
150+
if answer == 'q':
151+
break
152+
balance +=spin(balance)
153+
154+
print(f'Current balance: ${balance}')
155+
156+
if __name__ == '__main__':
157+
main()

0 commit comments

Comments
 (0)