From 7fff19efd073c75754bde8170fd398bb05e99b8b Mon Sep 17 00:00:00 2001 From: Boateng Prince Agyenim <163312213+Mmabiaa@users.noreply.github.com> Date: Wed, 8 Jan 2025 20:41:05 +0000 Subject: [PATCH] Uploaded Easy Level Directory - **This directory includes all implemented files for each program** --- assets/Easy Level Programs/City_Quiz.py | 92 ++++++++++ assets/Easy Level Programs/Rock_paper_game.py | 60 +++++++ assets/Easy Level Programs/number_guessing.py | 23 +++ .../random_password_generator.py | 48 ++++++ assets/Easy Level Programs/slot_game.py | 157 ++++++++++++++++++ .../Easy Level Programs/words_dictionary.py | 63 +++++++ 6 files changed, 443 insertions(+) create mode 100644 assets/Easy Level Programs/City_Quiz.py create mode 100644 assets/Easy Level Programs/Rock_paper_game.py create mode 100644 assets/Easy Level Programs/number_guessing.py create mode 100644 assets/Easy Level Programs/random_password_generator.py create mode 100644 assets/Easy Level Programs/slot_game.py create mode 100644 assets/Easy Level Programs/words_dictionary.py diff --git a/assets/Easy Level Programs/City_Quiz.py b/assets/Easy Level Programs/City_Quiz.py new file mode 100644 index 0000000..f32efb7 --- /dev/null +++ b/assets/Easy Level Programs/City_Quiz.py @@ -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. + + + + + + + diff --git a/assets/Easy Level Programs/Rock_paper_game.py b/assets/Easy Level Programs/Rock_paper_game.py new file mode 100644 index 0000000..33b4f25 --- /dev/null +++ b/assets/Easy Level Programs/Rock_paper_game.py @@ -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() diff --git a/assets/Easy Level Programs/number_guessing.py b/assets/Easy Level Programs/number_guessing.py new file mode 100644 index 0000000..328ce88 --- /dev/null +++ b/assets/Easy Level Programs/number_guessing.py @@ -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() \ No newline at end of file diff --git a/assets/Easy Level Programs/random_password_generator.py b/assets/Easy Level Programs/random_password_generator.py new file mode 100644 index 0000000..3377ef0 --- /dev/null +++ b/assets/Easy Level Programs/random_password_generator.py @@ -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() + + diff --git a/assets/Easy Level Programs/slot_game.py b/assets/Easy Level Programs/slot_game.py new file mode 100644 index 0000000..9dc88ba --- /dev/null +++ b/assets/Easy Level Programs/slot_game.py @@ -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() \ No newline at end of file diff --git a/assets/Easy Level Programs/words_dictionary.py b/assets/Easy Level Programs/words_dictionary.py new file mode 100644 index 0000000..da030f5 --- /dev/null +++ b/assets/Easy Level Programs/words_dictionary.py @@ -0,0 +1,63 @@ +from PyDictionary import PyDictionary + +# A simple word dictionary program + +dictionary = PyDictionary() + + + +def Synonym(word): + print(dictionary.synonym(word)) + +def Antonym(word): + print(dictionary.antonym(word)) + +def Quit(): + print('Thanks for using this software...😁👌') + +def Meaning(word): + print(dictionary.meaning(word)) + + +def Main(): + + options = (1, 2, 3) + + print('A Simple Word Dictionary Program') + + while True: + + print('Menu \n 1. Get Meanings 2. Get Synonyms 3. Get Antonyms 4. Quit') + + + user_choice = None + try: + user_choice = int(input('Enter a choice: ')) + + + if user_choice in options: + word = input('Enter a word: ') + if user_choice == 1: + Meaning(word) + elif user_choice == 2: + Synonym(word) + else: + Antonym(word) + elif user_choice == 4: + Quit() + break + else: + print('Enter a choice(1-4)') + + except ValueError: + print('Invalid Option!') + + print('') + + + + + + + +Main() \ No newline at end of file