Posts

Showing posts from April, 2021

Coffee machine coding in Python

 Create main.py file and paste the code below from menu import Menu, MenuItem from coffee_maker import CoffeeMaker from money_machine import MoneyMachine menu = Menu() coffeemaker = CoffeeMaker() moneymachine = MoneyMachine() # menuitem = MenuItem() machine_on = True while machine_on: user_input = input("What would you like to have? ") if user_input == 'report': print(coffeemaker.report()) elif user_input == 'off': machine_on = False else: item = menu.find_drink(user_input) is_available = coffeemaker.is_resource_sufficient(item) if is_available: recieve_money = moneymachine.make_payment(item.cost) if recieve_money: coffeemaker.make_coffee(item) Create Coffeemaker.py file and paste the code below class CoffeeMaker: """Models the machine that makes the coffee""" def __init__(self): self.resources = { "water": 300, "milk"...

Quiz game in Python

 Create main.py and paste code below from game_data import data import random from art import logo, vs from replit import clear def get_random_account(): """Get data from random account""" return random.choice(data) def format_data(account): """Format account into printable format: name, description and country""" name = account["name"] description = account["description"] country = account["country"] # print(f'{name}: {account["follower_count"]}') return f"{name}, a {description}, from {country}" def check_answer(guess, a_followers, b_followers): """Checks followers against user's guess and returns True if they got it right. Or False if they got it wrong.""" if a_followers > b_followers: return guess == "a" else: return guess == "b" def game(): print(logo) score = 0 game_sh...

Number guessing game with Python

Create art.py file and import the following code: logo = """ ) ( /( ) )\()) ( ) ( /( ( ( ( ( ( ( ( ( ) ) ( ((_)\ ))\ ( )\()) ))\ )( )\))( ))\ ))\ ( ( )\))( ( /( ( ))\ _((_) /((_) )\ '((_)\ /((_)(()\ ((_))\ /((_) /((_))\ )\ ((_))\ )(_)) )\ ' /((_) | \| |(_))( _((_)) | |(_)(_)) ((_) (()(_)(_))( (_)) ((_)((_) (()(_)((_)_ _((_)) (_)) | .` || || || ' \()| '_ \/ -_) | '_| / _` | | || |/ -_)(_-<(_-< / _` | / _` || ' \()/ -_) |_|\_| \_,_||_|_|_| |_.__/\___| |_| \__, | \_,_|\___|/__//__/ \__, | \__,_||_|_|_| \___| |___/ |___/ ""...

Blackjack game with Python

Create art.py file and paste code below logo = """ .------. _ _ _ _ _ |A_ _ |. | | | | | | (_) | | |( \/ ).-----. | |__ | | __ _ ___| | ___ __ _ ___| | __ | \ /|K /\ | | '_ \| |/ _` |/ __| |/ / |/ _` |/ __| |/ / | \/ | / \ | | |_) | | (_| | (__| <| | (_| | (__| < `-----| \ / | |_.__/|_|\__,_|\___|_|\_\ |\__,_|\___|_|\_\\ | \/ K| _/ | `------' |__/ """ Inside main.py file, paste this code from art import logo print(logo) import random cards = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10] first_card_player = random.choice(cards) second_card_player = random.choice(cards) player_cards = [first_card_player, second_card_player] first_card_computer = random.choice(cards) second_card_computer = rando...

Encryption and Decryption using Python

 In this tutorial, I am going to show you how can we encrypt and decrypt text using python: Here is the code: Create->. Main.py copy and pest below code alphabet = [ ' ','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',' ','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' ] direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n") text = input...

Hangman Game in Python

  #Step 1 Create->            main.py Insert these code: import random import hangman_art.py import word_list.py from replit import clear print(hangman_art.logo) word = random.choice(hangman_words.word_list) blank_map = [] for i in word: blank_map.append('_') print(word) count = len(word) end_of_the_game = False while count != 0 and not end_of_the_game:    clear() print(count) user_guessed = input("Enter word: \n") for letter in range(len(word)): if word[letter] == user_guessed: blank_map[letter] = user_guessed if user_guessed not in word: print(hangman_art.stages[count]) count -= 1 if '_' not in blank_map: end_of_the_game = True print(blank_map) if count == 0: print("You lost the game") else: print("You won the game") Create->             hangman_art.py Insert these code: stages = [''' +---+ | | O | /|\ | / \ | | ========= ''', ''' ...

Strong Password Generator Project in Python

  #Password Generator Project import random letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] symbols = ['!', '#', '$', '%', '&', '(', ')', '*', '+...

Rock Paper And Scissor Game with Python

Here is the code for Rock paper and scissor game   rock = ''' _______ ---' ____) (_____) (_____) (____) ---.__(___) ''' paper = ''' _______ ---' ____)____ ______) _______) _______) ---.__________) ''' scissors = ''' _______ ---' ____)____ ______) __________) (____) ---.__(___) ''' user_input = input(" Choose any one number corrospond from the list-- 1: Rock, 2: Paper and 3: scissors \n") user_input = int(user_input) import random computer_choice = random.randint(1, 3) possible_list = [rock, paper, scissors] if user_input < 1 or user_input > 3: print("Input again") else: if computer_choice == user_input: print(f"Computer choice is: \n {possible_list[computer_choice-1]}") print(f"Your choice is:\n {possible_list[user_input-1]}") print("Draw") ...