Python
1.03.2024 r.
24. Number Manipulation and F Strings in Python
25. [Interactive Coding Exercise] Life in Weeks
2.03.2024 r.
26. Day 2 Project: Tip Calculator
1) proste rozwiązanie
print("Hello in Tip Calculator")
bill = input ("What was the total bill? ")
tip = input ("What percentage tip would you like to give? 10, 12, or 15? ")
people = input ("How many people to split the bill? ")
bill_as_float = float(bill)
tip_as_int = int(tip)
pay = (bill_as_float * (1 + tip_as_int/100)) / int(people)
print (f"Each person should pay: {pay} ")
2) zaokrąglam końcówki
print("Hello in Tip Calculator")
bill = input ("What was the total bill? ")
tip = input ("What percentage tip would you like to give? 10, 12, or 15? ")
people = input ("How many people to split the bill? ")
bill_as_float = float(bill)
tip_as_int = int(tip)
pay = (bill_as_float * (1 + tip_as_int/100)) / int(people)
final_amount = round(pay, 2)
print (f"Each person should pay: {final_amount} ")
3. Wymuszone formatowanie
print("Hello in Tip Calculator")
bill = input ("What was the total bill? ")
tip = input ("What percentage tip would you like to give? 10, 12, or 15? ")
people = input ("How many people to split the bill? ")
bill_as_float = float(bill)
tip_as_int = int(tip)
pay = (bill_as_float * (1 + tip_as_int/100)) / int(people)
final_amount = round(pay, 2)
final_amount = "{:.2f}".format(pay)
print (f"Each person should pay: {final_amount} ")
27. You are already in the top 50%
28. Day 3 Goals: what we will make by the end of the day
29. Get Access to the Monthly App Brewery Newsletter
30. Control Flow with if / else and Conditional Operators
3.03.2024 r.
30. Control Flow with if / else and Conditional Operators
31. [Interactive Coding Exercise] Odd or Even? Introducing the Modulo
Kod sprawdza czy wprowadzona liczba jest parzysta czy nieparzysta. (The Modulo Operator 5 % 2 / # result is 1 )
number = int(input())
if number % 2 == 0:
print("This is an even number.")
else:
print("This is an odd number.")
32. Nested if statements and elif statements (użycie „Elif”
if height >=120:
print ("you can ride the rollercoaster!")
age = int(input("What is your age?")
if age <12:
print ("Please pay $5.")
elif age <=18:
print("Please pay $7.")
else:
print (please pay $12.")
else:
print("Sorry, you have to grow taller before you can ride.")
33. [Interactive Coding Exercise] BMI 2.0
1. BMI 1.0
height = input()
weight = input()
weight_as_int = int(weight)
height_as_float = float(height)
bmi = weight_as_int / height_as_float ** 2
bmi_as_int = int(bmi)
print(bmi_as_int)
2. BMI 2.0
height = input("what is your height in m (ex.1.8):")
weight = input("what is your weight in kg (ex.80):")
weight_as_int = int(weight)
height_as_float = float(height)
bmi = weight_as_int / height_as_float ** 2
bmi_as_int = bmi
if bmi_as_int < 18.5:
print(f"Your BMI is {bmi_as_int}, you are underweight")
elif bmi_as_int < 25:
print(f"Your BMI is {bmi_as_int}, you have a normal weight.")
elif bmi_as_int < 30:
print(f"Your BMI is {bmi_as_int}, you are slightly overweight.")
elif bmi_as_int < 35:
print(f"Your BMI is {bmi_as_int}, you are obese.")
elif bmi_as_int >= 35:
print(f"Your BMI is {bmi_as_int}, you are clinically obese.")
34. [Interactive Coding Exercise] Leap Year
year=int(input("Enter a year: "))
if year%4==0:
if year%100==0:
if year%400==0:
print("This is a leap year")
else:
print("This is not a leap year")
else:
print("This is a leap year")
else:
print("Not leap year")
35. Multiple If Statements in Succession
if / elif / else
if condition1:
do A
elif condition2:
do B
else:
d C
Multiple if
if condition1:
do A
if condition2:
do B
if condition3:
do C
print(„Welcome to the rollercoaster!”)
height = int(input(„What is your height in cm? „))
bill = 0
if height >= 120:
print(„You can ride the rollercoaster!”)
age = int(input(„What is your age? „))
if age < 12:
bill = 5
print(„Child tickets are $5.”)
elif age <= 18:
bill = 7
print(„Youth tickets are $7.”)
else:
bill = 12
print(„Adult tickets are $12.”)
wants_photo = input(„Do you want a photo taken? Y or N. „)
if wants_photo == „Y”:
bill += 3
print(f”Your final bill is ${bill}”)
else:
print(„Sorry, you have to grow taller before you can ride.”)
36. [Interactive Coding Exercise] Pizza Order Practice
print("Thank you for choosing Python Pizza Deliveries!")
size = input("What size pizza do you want? S, M, or L?")
add_pepperoni = input("Do you want pepperoni? Y or N?")
extra_cheese = input("Do you want extra cheese? Y or N?")
bill = 0
if size =="S":
bill += 15
elif size =="M":
bill += 20
elif size == "L":
bill += 25
if add_pepperoni == "Y":
if size == "S":
bill += 2
else:
bill += 3
if extra_cheese == "Y":
bill += 1
print (f"Your final bill is: ${bill}. ")
37. Logical Operators
print(„Welcome to the rollercoaster!”)
height = int(input(„What is your height in cm? „))
bill = 0
if height >= 120:
print(„You can ride the rollercoaster!”)
age = int(input(„What is your age? „))
if age < 12:
bill = 5
print(„Child tickets are $5.”)
elif age <= 18:
bill = 7
print(„Youth tickets are $7.”)
elif age >= 45 and age <= 55:
print(„Everything is going to be ok. Have a free ride on us!”)
else:
bill = 12
print(„Adult tickets are $12.”)
wants_photo = input(„Do you want a photo taken? Y or N. „)
if wants_photo == „Y”:
bill += 3
print(f”Your final bill is ${bill}”)
else:
print(„Sorry, you have to grow taller before you can ride.”)
38. [Interactive Coding Exercise] Love Calculator
print("The Love Calculator is calculating your score...")
name1 = input("What is your name?") # What is your name?
name2 = input("What is their name?") # What is their name?
combined_names = name1 + name2 #we will add both names together
lower_names = combined_names.lower() #we will change the letters to lower case so that there are no mistakes
t = lower_names.count("t")
r = lower_names.count("r")
u = lower_names.count("u")
e = lower_names.count("e")
first_digit = t + r + u + e
l = lower_names.count("l")
o = lower_names.count("o")
v = lower_names.count("v")
e = lower_names.count("e")
second_digit = l + o + v + e
score = int(str(first_digit) + str(second_digit) )
if (score < 10) or (score > 90):
print (f"Your score is {score}, you go together like coke and mentos.")
elif (score>=40) and (score<=50):
print (f"Your score is {score}, you are alright together.")
else:
print (f"Your score is {score}.")
39. Day 3 Project: Treasure Island
10.03.2024 r. niedziela
Dziś kontynułuje naukę, uzupełniam wiedzę poza bootcampem.
– Pętle w pytonie (While, Break, Continue, Pętle For)
17.03.2024 niedziela
Uzupełniam czego nie zrobiłem w tygodniu.
choice1 = input ('You\'re at a cross road. Where do you want to go? Type "left" or "right" \n').lower()
if choice1 == left:
choice2 = input('You\'ve come to a lake. There is an island in the middle of the the lake. Type "wait" to wait for a boat. Type "swim" to swim across. \n').lower()
if choice2 == wait:
choice3 = input("You arrive at the island unharmed. There is a house with 3 doors One red, one yellow and one blue. Which colour do you choose? \n").lower()
if choice3 == red:
print("It's a room full of fire. Game Over.")
elif choice3 == yellow:
print("You found the treasure! You Win!")
elif choice3 == blue:
print("You enter a room of beasts. Game Over.")
else:
print("You fell into a hole. Game Over.")
/ losowość/
import random
c = random.randint(0, 1)
if c == 0:
print(„Heads”)
else :
(print(„Tails”))
18.03.2024 godz.4:00
Program do losowania kto zapłaci za obiad:
names = names_string.split(",")
import random
# Get the total number of items in list
num_items = len(names)
# Generate random numbers between 0 and the last index.
random_choice = random.randint(0, num_items - 1)
# Pick out random person from list of names using the random number.
person_who_will_pay = names[random_choice]
print(person_who_will_pay + "is going to buy the meal today!")
24.03.2024 r. niedziela / Day 4 Project: Rock Paper Scissors
import random
rock = '''
_______
---' ____)
(_____)
(_____)
(____)
---.__(___)
'''
paper = '''
_______
---' ____)____
______)
_______)
_______)
---.__________)
'''
scissors = '''
_______
---' ____)____
______)
__________)
(____)
---.__(___)
'''
game_images = [rock, paper, scissors]
user_choice = int(input("What do you choose? Type 0 for Rock, 1 for Paper or 2 for Scissors.\n"))
if user_choice >= 3 or user_choice < 0:
print("You typed an invalid number, you lose!")
else:
print(game_images[user_choice])
computer_choice = random.randint(0, 2)
print("Computer chose:")
print(game_images[computer_choice])
if user_choice == 0 and computer_choice == 2:
print("You win!")
elif computer_choice == 0 and user_choice == 2:
print("You lose")
elif computer_choice > user_choice:
print("You lose")
elif user_choice > computer_choice:
print("You win!")
elif computer_choice == user_choice:
print("It's a draw")
print(game_images[user_choice])
