Skip to content

Commit 441ab07

Browse files
2 parents 996d05b + 4bcca7d commit 441ab07

5 files changed

Lines changed: 1168 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Python Package using Conda
2+
3+
on: [push]
4+
5+
jobs:
6+
build-linux:
7+
runs-on: ubuntu-latest
8+
strategy:
9+
max-parallel: 5
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Set up Python 3.10
14+
uses: actions/setup-python@v3
15+
with:
16+
python-version: '3.10'
17+
- name: Add conda to system path
18+
run: |
19+
# $CONDA is an environment variable pointing to the root of the miniconda directory
20+
echo $CONDA/bin >> $GITHUB_PATH
21+
- name: Install dependencies
22+
run: |
23+
conda env update --file environment.yml --name base
24+
- name: Lint with flake8
25+
run: |
26+
conda install flake8
27+
# stop the build if there are Python syntax errors or undefined names
28+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
29+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
30+
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
31+
- name: Test with pytest
32+
run: |
33+
conda install pytest
34+
pytest

HANGMAN.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Hangman in Python
2+
import random
3+
4+
hangman_art = {0: (" ",
5+
" ",
6+
" "),
7+
1: (" o ",
8+
" ",
9+
" "),
10+
2: (" o ",
11+
" | ",
12+
" "),
13+
3: (" o ",
14+
"/| ",
15+
" "),
16+
4: (" o ",
17+
"/|\\",
18+
" "),
19+
5: (" o ",
20+
"/|\\",
21+
"/ "),
22+
6: (" o ",
23+
"/|\\",
24+
"/ \\")}
25+
26+
words = ("aardvark", "alligator", "alpaca", "ant", "anteater",
27+
"antelope", "ape", "armadillo", "baboon", "badger", "bat",
28+
"bear", "beaver", "bee", "bison", "boar", "buffalo",
29+
"butterfly", "camel", "capybara", "caribou", "cat",
30+
"caterpillar", "cattle", "chamois", "cheetah", "chicken",
31+
"chimpanzee", "chinchilla", "chough", "clam", "cobra", "cockroach",
32+
"cod", "coyote", "crab", "crane", "crocodile", "crow", "curlew", "deer",
33+
"dinosaur", "dog", "dogfish", "dolphin", "donkey", "dormouse", "dotterel", "dove",
34+
"elephant", "elk", "emu", "falcon", "ferret", "finch", "fish", "flamingo",
35+
"fly", "fox", "frog", "gaur", "gazelle", "gerbil", "giraffe", "gnat", "gnu",
36+
"goat", "goldfinch", "goldfish", "goose", "gorilla", "goshawk", "grasshopper",
37+
"grouse", "guanaco", "gull", "hamster", "hare", "hawk", "hedgehog", "heron", "herring", "hippopotamus",
38+
"hornet", "horse", "human", "hummingbird", "hyena", "ibex", "ibis", "jackal", "jaguar", "jay",
39+
"jellyfish", "kangaroo", "kingfisher", "koala", "kookabura", "kouprey", "kudu", "lapwing", "lark",
40+
"lemur", "leopard", "lion", "llama", "lobster", "locust", "loris", "louse", "lyrebird", "magpie", "mallard",
41+
"manatee", "mandrill", "mantis", "marten", "meerkat", "mink", "mole", "mongoose", "monkey", "moose", "mosquito",
42+
"mouse", "mule", "narwhal", "newt", "nightingale", "octopus", "okapi", "opossum", "oryx", "ostrich", "otter",
43+
"owl", "ox", "oyster", "panda", "panther", "parrot", "partridge", "peafowl", "pelican", "penguin", "pheasant",
44+
"pig", "pigeon", "polar-bear", "pony", "porcupine", "porpoise", "quail", "quelea", "quetzal", "rabbit", "raccoon",
45+
"rail", "ram", "rat", "raven", "red-deer", "red-panda", "reindeer", "rhinoceros", "rook", "salamander", "salmon",
46+
"sand-dollar", "sandpiper", "sardine", "scorpion", "seahorse", "seal", "shark", "sheep", "shrew", "skunk", "snail",
47+
"snake", "sparrow", "spider", "spoonbill", "squid", "squirrel", "starling", "stingray", "stoat", "stork", "swallow", "swan",
48+
"tapir", "tarsier", "termite", "tiger", "toad", "trout", "turkey", "turtle", "viper", "vulture", "wallaby", "walrus", "wasp",
49+
"weasel", "whale", "wildcat", "wolf", "wolverine", "wombat", "woodcock", "woodpecker", "worm", "wren", "yak", "zebra")
50+
51+
def display_man(wrong_guesses):
52+
print("**********")
53+
for line in hangman_art[wrong_guesses]:
54+
print(line)
55+
print("**********")
56+
57+
def display_hint(hint):
58+
print(" ".join(hint))
59+
60+
def display_answer(answer):
61+
print(" ".join(answer))
62+
63+
def main():
64+
answer = random.choice(words)
65+
hint = ["_"] * len(answer)
66+
wrong_guesses = 0
67+
guessed_letters = set()
68+
is_running = True
69+
70+
while is_running:
71+
display_man(wrong_guesses)
72+
display_hint(hint)
73+
guess = input("Enter a letter: ").lower()
74+
75+
if len(guess) != 1 or not guess.isalpha():
76+
print("Invalid input")
77+
continue
78+
79+
if guess in guessed_letters:
80+
print(f"{guess} is already guessed")
81+
continue
82+
83+
guessed_letters.add(guess)
84+
85+
if guess in answer:
86+
for i in range(len(answer)):
87+
if answer[i] == guess:
88+
hint[i] = guess
89+
else:
90+
wrong_guesses += 1
91+
92+
if "_" not in hint:
93+
display_man(wrong_guesses)
94+
display_answer(answer)
95+
print("YOU WIN! THERE IS NOONE BETTER THAN YOU KING")
96+
is_running = False
97+
elif wrong_guesses >= len(hangman_art) - 1:
98+
display_man(wrong_guesses)
99+
display_answer(answer)
100+
print("YOU LOSE! BUT YOU SHOULD TRY AGAIN!!!!")
101+
is_running = False
102+
103+
if __name__ == "__main__":
104+
main()

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# projects.python

banking_slot.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# python banking program
2+
3+
4+
def show_balance(balance):
5+
6+
print(f"Your balance is ${balance:.2f}")
7+
8+
def deposit():
9+
10+
amount = float(input("Enter your amount sir:"))
11+
12+
if amount < 0:
13+
print("amount must be greater than 0")
14+
return 0
15+
else:
16+
return amount
17+
18+
def withdraw(balance):
19+
amount = float(input("enter your amount sir:"))
20+
if amount > balance:
21+
print("insufficient funds")
22+
return 0
23+
elif amount < 0:
24+
print("amount must be greater than 0")
25+
return 0
26+
else:
27+
return amount
28+
29+
def main():
30+
balance = 0
31+
is_running = True
32+
33+
while is_running:
34+
print("*******")
35+
print("BANKING PROGRAM WELCOMES YOU")
36+
print("*******")
37+
38+
print("1.show_balance")
39+
40+
print("2.deposit")
41+
42+
print("3.withdraw")
43+
44+
print("4.exit")
45+
46+
47+
choice = input("enter your choice (1-4): ")
48+
49+
if choice == '1' :
50+
show_balance(balance)
51+
elif choice == '2' :
52+
balance += deposit()
53+
elif choice == '3' :
54+
balance -= withdraw(balance)
55+
elif choice == '4' :
56+
is_running = False
57+
else :
58+
print("this is invalid choice")
59+
60+
61+
print("Thank you have a nice day")
62+
63+
main()
64+

0 commit comments

Comments
 (0)