Skip to content

Uploaded Easy Level Directory #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions assets/Easy Level Programs/City_Quiz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Simple quiz that asks questions, and display results


def Quiz_Question(): # A function that stores quiz questions and answers and return quiz and score

score = 0

quiz = {# A dictionary containing quiz questions and answers
'questions 1':{
'question': 'What is the capital of France?: ',
'answer': 'Paris'
},
'questions 2':{
'question': 'What is the capital of Germany?: ',
'answer': 'Berlin'
},
'questions 3':{
'question': 'What is the capital of Canada?: ',
'answer': 'Toronto'
},
'questions 4':{
'question': 'What is the capital of Italy?: ',
'answer': 'Rome'
},
'questions 5':{
'question': 'What is the capital of Spain?: ',
'answer': 'Madrid'
},
'questions 6':{
'question': 'What is the capital of Portugal?: ',
'answer': 'Lisbon'
},
'questions 7':{
'question': 'What is the capital of Switzerland?: ',
'answer': 'Bern'
},
'questions 8':{
'question': 'What is the capital of Netherland?: ',
'answer': 'Amsterdam'
},'questions 9':{
'question': 'What is the capital of Austra?: ',
'answer': 'Vienna'
},'questions 10':{
'question': 'What is the capital of Russia?: ',
'answer': 'Moscow'
}
}
return score, quiz




def display_Quiz(quiz, score): # A function that displays quiz and results

for key, value in quiz.items(): # A loop to iterate through the quiz items and display (questions and answers)
print(value['question']) # Printing each question in the quiz
user_answer = None

user_answer = input('Your answer: ').lower()

# conditions to validate results
if user_answer == value['answer'].lower():
print('Correct!😁')
score += 1
print(f'Your Score = {score}👌')
print(' ')

else:
print('Wrong!😢')
print(f'Correct Answer = {value['answer']}')
print(f'Your Score = {score}👌')
print(' ')

print(f'\n Total = {score} / 10')
percentage = (score / 10) * 100
print(f'Percentage = {percentage}%')
print(f'\n Thanks for participating...😁❤️')


def main(): # main function to run the program.
score, quiz = Quiz_Question()

display_Quiz(quiz, score)

main() # calling the main function to run the program.







60 changes: 60 additions & 0 deletions assets/Easy Level Programs/Rock_paper_game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

import random # A library to generate random choices

# variables to store options
ROCK = 'r'
SCISSORS = 's'
PAPER = 'p'

emojis = {ROCK:'🪨', PAPER:'📃', SCISSORS:'✂️'} # A dictionary to store option keys with emoji values
options = tuple(emojis.keys()) # A tuple to store option values



def get_user_choice():# A function to return a user choice

user_input = input("Rock, paper, or scissors? (r/p/s): ")

if user_input in options:
return user_input
else:
print("Invalid input")



def display_choices(cpu, user_input): # A function that displays the choices (cpu, user_input)

print(f"You chose {emojis[user_input]}")
print(f"Computer chose {emojis[cpu]}")


def determine_winner(cpu, user_input): # A function that determines the winner

if ((user_input == ROCK and cpu == SCISSORS) or
(user_input == SCISSORS and cpu == PAPER) or
(user_input == PAPER and cpu == ROCK)):
print("You won!🥳")
elif(user_input == cpu):
print("You tie!😎")
else:
print("You lose!😢")


def Game():# A function to return various functions to start the game.
while True:
user_input = get_user_choice()

cpu = random.choice(options)

display_choices(cpu, user_input)

determine_winner(cpu, user_input)

Continue = input("Do you want to continue (y/n)😊: ").lower()

if Continue == 'n':
print("Thanks for playing!😁")
break

# Calling the Game function to initialize the program.
Game()
23 changes: 23 additions & 0 deletions assets/Easy Level Programs/number_guessing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# A simple number guessing game using python.
import random # For random numbers

def number_guessing():
number = random.randint(1,100)
while True:

try:
guess = int(input("Guess a number from 1 to 100: "))

if number == guess:
print("Congratulations! You guessed the number!")
break
elif number > guess:
print("Too low!")
else:
print("Too high!")


except ValueError:
print("Enter a valid number")

number_guessing()
48 changes: 48 additions & 0 deletions assets/Easy Level Programs/random_password_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# A simple program that helps users to get a password idea.
import random
import string

def Storage():
characters = list(string.ascii_letters + string.digits + '!@#$%^&*()')

options = ['y', 'n']

return characters, options

def get_password(characters, options):

while True:
user_choice = input('Do you want to generate a new password (y/n): ').lower()

if user_choice not in options:
print('Enter a valid choice (y/n)')


else:
if user_choice == 'y':
password_length = int(input('Enter password length: '))
random.shuffle(characters)

password = []

for x in range(password_length):
password.append(random.choice(characters))

random.shuffle(password)

password = ''.join(password)

print(password)

else:
print('Thanks for using this program...😁')
break

def Main():
characters, options = Storage()

get_password(characters, options)

Main()


157 changes: 157 additions & 0 deletions assets/Easy Level Programs/slot_game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import random

# Constant variables
MAX_LINE = 3
MAX_BET = 100
MIN_BET = 1

ROWS = 3
COLS = 3

symbols_count = {
'A':2,
'B':4,
'C':6,
'D':8
}

symbols_values = {
'A':5,
'B':3,
'C':4,
'D':2
}


def check_winnings(columns, lines, bet, values):
winnings = 0
lines_won = []
for line in range(lines):
symbol = columns[0][line]
for column in columns:
symbol_to_check = column[line]
if symbol != symbol_to_check:
break
else:
winnings += values[symbol] * bet
lines_won.append(line + 1)

return winnings, lines_won




def get_slot_machine_spin(rows, cols, symbols):
all_symbols = []
for symbol, symbols_count in symbols.items():
for _ in range(symbols_count):
all_symbols.append(symbol)

columns = []
for _ in range(cols):
column = []
current_symbols = all_symbols[:]
for _ in range(rows):
value = random.choice(current_symbols)
current_symbols.remove(value)
column.append(value)
columns.append(column)

return columns

def print_slot(columns):
for row in range(len(columns[0])):
for i, column in enumerate(columns):
if i != len(columns)-1:
print(column[row],end=' | ')
else:
print(column[row], end='')
print()




def deposit():
while True:
amount = input('How much would you like to deposit: $')
if amount.isdigit():
amount = float(amount)
if amount > 0:
break
else:
print('Amount must be greater than zero!')
else:
print('Please enter a number!')
print('----------------------------------------------------------------')

return amount

def get_number_of_lines():
while True:
lines = input('Enter the number of lines to bet on(1-' + str(MAX_LINE) + '): ')
if lines.isdigit():
lines = int(lines)
if 0 < lines <= MAX_LINE:
break
else:
print('Enter a valid number of lines!')
else:
print('Please enter a number!')
print('----------------------------------------------------------------')

return lines

def get_bet():
while True:
amount = input('How much would you like to bet: $')
if amount.isdigit():
amount = float(amount)
if MIN_BET <= amount <= MAX_BET:
break
else:
print(f'Betting amount must be between ${MIN_BET} - ${MAX_BET} !')
else:
print('Please enter a number!')

print('----------------------------------------------------------------')

return amount

def spin(balance):
lines = get_number_of_lines()
while True:
bet = get_bet()
total_bet = bet * lines

if total_bet > balance:
print('You do not have enough balance to bet!')
print(f'Current balance: ${balance}')
print('----------------------------------------------------------------')
else:
break

print(f'You are betting ${bet} on ${lines} lines.\n Total bet: ${total_bet}')
print('----------------------------------------------------------------')

slots = get_slot_machine_spin(ROWS, COLS, symbols_count)
print_slot(slots)
winnings, lines_won = check_winnings(slots, lines, bet, symbols_values)
print('----------------------------------------------------------------')
print(f'You won ${winnings}. ')
print(f'You won on lines:', *lines_won)
print('----------------------------------------------------------------')
return winnings - total_bet

def main():
balance = deposit()
while True:
print(f'Current balance: ${balance}')
answer = input('Press enter to play (q to quit): ')
if answer == 'q':
break
balance +=spin(balance)

print(f'Current balance: ${balance}')

if __name__ == '__main__':
main()
Loading
Loading