Skip to content
Open
104 changes: 104 additions & 0 deletions #For Loop in Python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#For Loop
fruits = ["apple", "banana", "cherry", "kiwi", "mango"]
for a in fruits:
print(a)
print("I love " + a)

#Average Height Calcuation
student_heights = input("Input a list of student heights\n").split( )
for n in range(0,len(student_heights)):
student_heights[n] = int(student_heights[n])
total_height = 0
for height in student_heights:
total_height += height
number_of_students = 0
for student in range(0, len(student_heights)):
number_of_students = student + 1
average_height = round(total_height / number_of_students)
print(f"The average height is {average_height}")

#High score exercise
student_scores = input("Input a list of student scores: \n").split()
for n in range(0, len(student_scores)):
student_scores[n] = int(student_scores[n])
highest_score = 0
for score in student_scores:
if score > highest_score:
highest_score = score
print(f"The highest score in the class is: {highest_score}")

#For loop with range
for num in range(1, 21, 5):
print(num)

#Sum of numbers btw 1 and 100
total = 0
for num in range(1, 101):
total += num
print(total)

#Sum of even numbers btw 1 and 100
total = 0
for num in range(0, 101, 2):
total += num
print(total)
#OR
total_x = 0
for num in range(1, 101):
if num % 2 == 0:
total_x += num
print(total_x)

#Mini Project
#FizzBuzz Game
#write a program that automatically prints the solution to the FizzBuzz game, for the numbers 1 through 100.
for numbers in range(1, 101):
if numbers % 3 == 0 and numbers % 5 == 0:
print("FizzBuzz")
elif numbers % 3 == 0:
print("Fizz")
elif numbers % 5 == 0:
print("Buzz")
else:
print(numbers)


##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 = ['!', '#', '$', '%', '&', '(', ')', '*', '+']

print("Welcome to the PyPassword Generator!")
num_letters = int(input("How many letters would you like in your password?\n"))
num_symbols = int(input("How many symbols would you like?\n"))
num_numbers = int(input("How many numbers would you like\n"))
#Level 1
password = ""
for char in range(1, num_letters + 1):
rand_letter = random.choice(letters)
password += rand_letter
for char in range(1, num_symbols + 1):
rand_symbol = random.choice(symbols)
password += rand_symbol
for char in range(1, num_numbers + 1):
rand_number = random.choice(numbers)
password += rand_number
print(password)
#Or
#Level 2
password_list = []
for char in range(1, num_letters +1):
rand_letter = random.choice(letters)
password_list.append(rand_letter)
for char in range(1, num_symbols + 1):
rand_symbol = random.choice(symbols)
password_list.append(rand_symbol)
for char in range(1, num_numbers + 1):
rand_number = random.choice(numbers)
password_list.append(rand_number)
random.shuffle(password_list)
password = ""
for char in password_list:
password += char
print(f"Your password is {password}")
87 changes: 87 additions & 0 deletions #Randomization
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
##Randomization
import random
import esters_code

print(esters_code.tom)

random_number = random.randint(1,100)
print(random_number)

random_float = random.random() * 10
print(random_float)

love_score = random.randint(1, 100)
print(f"Your love score is {love_score}")

#Mini project
#Create random sides of a coin: Heads or Tails
test_seed = int(input("Create a seed number: "))
random.seed(test_seed)
#generate random integers btw 0 and 1
random_side =random.randint(0,1)
if random_side == 1:
print("Heads")
else:
print("Tails")

##Offset and Appending Items to List

states_of_america = ["Delaware", "Pennsylvania", "New Jersey", "Georgia", "Connecticut", "Massachusetts", "Maryland", "South Carolina", "New Hampshire", "Virginia", "New York", "North Carolina", "Rhode Island", "Vermont", "Kentucky", "Tennessee", "Ohio", "Louisiana", "Indiana", "Mississippi", "Illinois", "Alabama", "Maine", "Missouri", "Arkansas", "Michigan", "Florida", "Texas", "Iowa", "Wisconsin", "California", "Minnesota", "Oregon", "Kansas", "West Virginia", "Nevada", "Nebraska", "Colorado", "North Dakota", "South Dakota", "Montana", "Washington", "Idaho", "Wyoming", "Utah", "Oklahoma", "New Mexico", "Arizona", "Alaska",]
states_of_america.append("Esters Island")
states_of_america[0]
print(states_of_america[0])
states_of_america[-2] = "Monkey Land"
states_of_america.extend(["Cupy Date", "Detty December", "Monkey Land"])
states_of_america.insert(12, "Iceland")
states_of_america.remove("Iceland")
states_of_america.pop()
states_of_america.reverse()
states_of_america.sort()
print(states_of_america)

my_country = states_of_america.copy()
print(my_country)

###Mini Project 2
##Who is paying the bill?
#Get to randomly select a person to pay the bills from a list of names

import random

name_csv = input("Give me everybody's names,separated by a comma.")
names = name_csv.split(", ")
num_names = len(names)
random_num = random.randint(0, num_names - 1)
name_chosen = names[random_num]
print(f"{name_chosen} is going to pay for the meal, today.")

#Or use the random.choice() function
name_csv = input("Give me everybody's names,separated by a comma.")
names = name_csv.split(", ")
name_choice = random.choice(names)
print(f"{name_choice} is going to pay for the meal, today.")

#Nested lists
box = []
fruits = ["apple", "banana", "cherry", "strawberry", "mango", "grape", "orange", "melon", "kiwi", "pineapple"]
vegetables = ["carrot", "cabbage", "lettuce", "spinach", "cucumber", "tomato", "onion", "potato", "pea", "broccoli"]
box = [fruits, vegetables]
print(box)

#Mini Test
#Position of treasure using two-digit numbers

row1 = ["🟦", "🟦", "🟦"]
row2 = ["🟦", "🟦", "🟦"]
row3 = ["🟦", "🟦", "🟦"]
map = [row1, row2, row3]
print(f"{row1}\n{row2}\n{row3}")

position = input("Where do you want to put your treasure?")
row = int(position[0])
column = int(position[1])
selected_row = map[row - 1]
selected_row[column - 1] = "X"
#Or
map[row - 1][column - 1] = "X"
print(f"{row1}\n{row2}\n{row3}")
68 changes: 68 additions & 0 deletions #Rock, Paper, Scissors Game:.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
##Rock, Paper, Scissors Game:

rock = '''
_______
---' ____)
(_____)
(_____)
VK (____)
---.__(___)
'''
paper = '''
_______
---' ____)____
______)
_______)
VK _______)
---.__________)
'''
scissors = '''
_______
---' ____)____
______)
__________)
VK (____)
---.__(___)
'''
import random
fig = int(input("What do you choose? Type 0 for Rock, 1 for Paper or 2 for Scissors.\n"))
if fig == 0:
print(rock)
elif fig == 1:
print(paper)
else:
print(scissors)
#Computer's choice
print("Computer's choice:")
computer_choice = random.randint(0,2)
if computer_choice ==0:
print(rock)
elif computer_choice == 1:
print(paper)
else:
print(scissors)
#Game logic
if fig == computer_choice:
print("It's tie, give it another try")
fig = int(input("Pick another number:"))
if fig == 0:
print(rock)
elif fig == 1:
print(paper)
else:
print(scissors)
#Player wins
elif fig == 0 and computer_choice == 2:
print("You win! Do you want to play again?")
elif fig == 1 and computer_choice == 2:
print("You win! Do you want to play again?")
elif fig == 2 and computer_choice == 1:
print("You win! Do you want to play again?")
#Computer wins
if computer_choice == 0 and fig == 2:
print("You lose!, do you want to play again?")
elif computer_choice == 1 and fig == 0:
print("You lose!, do you want to play again?")
elif computer_choice == 2 and fig == 1:
print("You lose!, do you want to play again?")

48 changes: 48 additions & 0 deletions #Treasure Island.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#Treasure Island

print('''
*******************************************************************************
| | | |
_________|________________.=""_;=.______________|_____________________|_______
| | ,-"_,="" `"=.| |
|___________________|__"=._o`"-._ `"=.______________|___________________
| `"=._o`"=._ _`"=._ |
_________|_____________________:=._o "=._."_.-="'"=.__________________|_______
| | __.--" , ; `"=._o." ,-"""-._ ". |
|___________________|_._" ,. .` ` `` , `"-._"-._ ". '__|___________________
| |o`"=._` , "` `; .". , "-._"-._; ; |
_________|___________| ;`-.o`"=._; ." ` '`."\` . "-._ /_______________|_______
| | |o; `"-.o`"=._`` '` " ,__.--o; |
|___________________|_| ; (#) `-.o `"=.`_.--"_o.-; ;___|___________________
____/______/______/___|o;._ " `".o|o_.--" ;o;____/______/______/____
/______/______/______/_"=._o--._ ; | ; ; ;/______/______/______/_
____/______/______/______/__"=._o--._ ;o|o; _._;o;____/______/______/____
/______/______/______/______/____"=._o._; | ;_.--"o.--"_/______/______/______/_
____/______/______/______/______/_____"=.o|o_.--""___/______/______/______/____
/______/______/______/______/______/______/______/______/______/______/[TomekK]
*******************************************************************************
''')

print("Welcome to Treasure Island.")
print("Your mission is to find the treasure.")
choice1 = input("You're at a cross road. Where do you want to go? Type 'left' or 'right'\n")
lower_choice1 = choice1.lower()
if lower_choice1 == "left":
print("You have come to a lake. There is an island in the middle of the lake.")
choice2 = input("Type 'wait' to wait for a boat. Type 'swim' to swim across.\n")
lower_choice2 = choice2.lower()
if lower_choice2 == "wait":
print("You arrive at the island unharmed. There is a house with 3 doors. One red, one yellow and one blue.")
choice3 = input("Which colour do you choose?\n")
colour = choice3.lower()
if colour == "red":
print("You just got burned by the flame from a dinosaur mouth. Game Over.")
elif colour == "yellow":
print("You found the treasue and won the game. Congratulations! You are now rich. Get ready for the next adventure.")
else:
print("You got eaten by a blue dragon. Game Over.")
else:
print("You got attacked by an angry sea beast. Game Over.")
else:
print("You fell into a hole and died. Game Over.")

File renamed without changes.
68 changes: 68 additions & 0 deletions .github/100 Days Python Coding/Capstone Project 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Capstone Project: Blackjack Program
import random
from replit import clear

def deal_card():
cards = [11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10]
card = random.choice(cards)
return card

def cal_score(cards):
if sum(cards) == 21 and len(cards) == 2:
return 0
if 11 in cards and sum(cards) > 21:
cards.remove(11)
cards.append(1)
return sum(cards)

def compare(user_score, computer_score):
if user_score == computer_score:
return "It's a draw!"
elif computer_score == 0:
return "The computer has a blackjack. You lose!"
elif user_score == 0:
return "You got a blackjack. You win!"
elif user_score > 21:
return "You went over. You lose!"
elif computer_score > 21:
return "The computer went over. You win!"
else:
if user_score > computer_score:
return "You have a higher score. You win!"
elif computer_score > user_score:
return "The computer has a higher score. You lose!"

def blackjack():
your_card = []
computer_card = []
game_over = False
for i in range(2):
your_card.append(deal_card())
computer_card.append(deal_card())

while not game_over:
user_score = cal_score(your_card)
computer_score = cal_score(computer_card)
print(f"Your cards: {your_card}, current score: {user_score}")
print(f"Computer's first card:{computer_card[0]}")

if user_score == 0 or computer_score == 0 or user_score > 21:
game_over = True
else:
get_card = input("Type 'y' to get another card, type 'n' to pass: ")
if get_card == "y":
your_card.append(deal_card())
user_score = cal_score(your_card)
elif get_card == "n":
game_over = True

while computer_score != 0 and computer_score < 17:
computer_card.append(deal_card())
computer_score = cal_score(computer_card)
print(f"Your final hand: {your_card}, final score: {user_score}")
print(f"Computer's final hand: {computer_card}, final score: {computer_score}")
print(compare(user_score, computer_score))

while input("Do you want to play a game of Blackjack? Type 'y' or 'n': ") == "y":
clear()
blackjack()
Loading