Skip to content
Open

Day2 #16

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions day_01/01_basics/exercise/01_hello_v2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# TODO: Print the following in the console:
# Use variables for the name and programming language
# print("Hello! My name is Jeff")
# print("I am learning Python")
print("Hello! My name is Leng")
print("I am learning Python")

name = "Leng"
language = "Python"
print("Hello! My name is", name)
print("I am learning", language)
9 changes: 6 additions & 3 deletions day_01/01_basics/exercise/02_counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
print("Counter:", counter)

# Point up: Add one to the counter
# TODO: Change code here
# counter = counter + 1
counter += 1
print("Counter:", counter)

# Bonus: Multiply the score by 10
# TODO: Change code here
# counter = counter * 10
counter *= 10
print("Counter:", counter)

# Penalty: Decrease the score by 4
# TODO: Change code here
# counter = counter - 4
counter -= 4
print("Counter:", counter)
3 changes: 3 additions & 0 deletions day_01/01_basics/exercise/02_counter_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

# Point up: Add one to the counter
# TODO: Change code here
counter += 1
print("Counter:", counter)

# Bonus: Multiply the score by 10
# TODO: Change code here
counter *= 10
print("Counter:", counter)

# Penalty: Decrease the score 4
# TODO: Change code here
counter -= 4
print("Counter:", counter)
6 changes: 3 additions & 3 deletions day_01/01_basics/exercise/03_wishlist.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# TODO: Fill in the variables based on the item you want to buy
name = None # What is the name of the item?
price = None # How much is the item?
organic = None # Is it organic?
name = "iPhone 17" # What is the name of the item?
price = 100_000 # How much is the item?
organic = True # Is it organic?

# TODO: Then, print each information one line at a time
print(name)
Expand Down
18 changes: 10 additions & 8 deletions day_01/01_basics/exercise/04_expense_tracker_v2.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# TODO: Ask the user for three values
expense_1 = None # Let the user enter a number
expense_2 = None # Let the user enter a number
expense_3 = None # Let the user enter a number
expense_1 = int(input("Expense_1: ")) # Let the user enter a number
expense_2 = int(input("Expense_2: ")) # Let the user enter a number
expense_3 = int(input("Expense_3: ")) # Let the user enter a number

# TODO: Then, print each information one line at a time
print(expense_1)
print(expense_2)
print(expense_3)
print("Expense_1 :" , expense_1)
print("Expense_2 :" , expense_2)
print("Expense_3 :" , expense_3)



# TODO: Calculate the sum of the numbers
total = None
print(total)
total = int(expense_1) + int(expense_2) + int(expense_3)
print("Total:" , total)
15 changes: 8 additions & 7 deletions day_01/01_basics/exercise/04_expense_tracker_v3.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# TODO: Ask the user for three values
expense_1 = None # Let the user enter a number
expense_2 = None # Let the user enter a number
expense_3 = None # Let the user enter a number
expense_1 = int(input("Expense_1: ")) # Let the user enter a number
expense_2 = int(input("Expense_2: ")) # Let the user enter a number
expense_3 = int(input("Expense_3: ")) # Let the user enter a number

# TODO: Then, print each information one line at a time
print(expense_1)
print(expense_2)
print(expense_3)
print("Expense_1 :" , expense_1)
print("Expense_2 :" , expense_2)
print("Expense_3 :" , expense_3)

total = expense_1 + expense_2 + expense_3
print(total)

# TODO: Format this part using f-strings
print(expense_1, "+", expense_2, "+", expense_3, "=", total)
print(f"Expense_1: {expense_1} + Expense_2: {expense_2} + Expense_3: {expense_3} = {total}")

4 changes: 2 additions & 2 deletions day_01/01_basics/exercise/05_ice_ice_ice_baby.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ice = "Ice"
ice = "Ice " *3
baby = "Baby"

# TODO: Print "Ice Ice Ice Baby" using + and *
print()
print(ice + baby)
9 changes: 6 additions & 3 deletions day_01/01_basics/exercise/06_price_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
price_notification = "The price of {} is ${}."

# TODO: Post: Latte ($3.5)
print(price_notification)
formatted_price_notification = price_notification.format("Latte", 3.5)
print(formatted_price_notification)

# TODO: Post: Espresso ($2.75)
print(price_notification)
formatted_price_notification = price_notification.format("Espresso", 2.75)
print(formatted_price_notification)

# TODO: Post: Cappuccino ($4.0)
print(price_notification)
formatted_price_notification = price_notification.format("Cappuccino", 4.0)
print(formatted_price_notification)
23 changes: 9 additions & 14 deletions day_01/01_basics/exercise/07_sales_tracker.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
# Ask the cost and pax or count for three separate items
item_cost_1 = int(input("Item cost 1: "))
item_count_1 = int(input("Item count 1: "))
item_cost_1 = int(input("Item cost 1: ")) # Let the user enter a number
item_count_1 = int(input("Item count 1: ")) # Let the user enter a number

item_cost_2 = int(input("Item cost 2: "))
item_count_2 = int(input("Item count 2: "))
item_cost_2 = int(input("Item cost 2: ")) # Let the user enter a number
item_count_2 = int(input("Item count 2: ")) # Let the user enter a number

item_cost_3 = int(input("Item cost 3: "))
item_count_3 = int(input("Item count 3: "))
item_cost_3 = int(input("Item cost 3: ")) # Let the user enter a number
item_count_3 = int(input("Item count 3: ")) # Let the user enter a number

# Calculate the total
total = (
(item_cost_1 * item_count_1)
+ (item_cost_2 * item_count_2)
+ (item_cost_3 * item_count_3)
)
print(total)
#calculate total sales
total_sales = (item_cost_1 * item_count_1) + (item_cost_2 * item_count_2) + (item_cost_3 * item_count_3)
print("Total sales: ", total_sales)
11 changes: 11 additions & 0 deletions day_01/01_basics/exercise/08_height_requirment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
minimum_height =138

# Ask the user for the following inputs
user_height = int(input("Enter your height in cm: "))

# Notify user if they can enter the ride
can_enter_ride = user_height >= minimum_height
print("You can enter the ride")

if not can_enter_ride:
print("Sorry, you have to grow taller before you can ride.")
10 changes: 10 additions & 0 deletions day_01/01_basics/exercise/09_valid_score.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Range minimum and maximum bounds
min_score = 0
max_score = 100

# ENter user input
number = int(input("Enter your score: "))

# Notify user if the number is a valid score
valid_score = min_score <= number <= max_score
print("Valid score:", valid_score)
10 changes: 10 additions & 0 deletions day_01/01_basics/exercise/10_login_system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Expected password
correct_password = "pass"

# Enter user password
password_input = input("Please provide password: ")

# Notify user if the password is valid
correct_password_given = password_input == correct_password
print("Access:", correct_password_given)

11 changes: 11 additions & 0 deletions day_01/01_basics/exercise/10_login_system_v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Expected password
correct_password = "pass"

# Enter user password
password_input = input("Please provide password: ")

# TODO: Notify user if the password is valid
correct_password_given = correct_password == password_input

if correct_password_given:
print("Access granted")
2 changes: 2 additions & 0 deletions day_01/01_basics/notes/05_input/01_input.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
user_input = input()
print(user_input)


28 changes: 28 additions & 0 deletions day_01/01_basics/notes/05_input/sample.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
password = input("Enter your password: ")
while password != "pass":
print("Incorrect password, try again.")
password = input("Enter your password: ")


def greetings(name):
print(f"Hello name ! Nice to meet you.")

greetings(name)

def product(x, y, z=1):
result = x * y * z
print(f"The product is: {result}")


def product(x, y, z=1):
result = x * y * z
return result

output = product(x=1, y=2, z=3) * 5
print(f"The product is: {output}")


try:
number_input = int(input("Number:"))
except:
print("Invalid input")
13 changes: 8 additions & 5 deletions day_01/02_control_flow/exercise/07_sales_tracker_v2.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# TODO: Ask the user how many items will be calculated
input_count = None
input_count = int(input("How many items will you enter? "))
total = 0

# TODO: Use a for loop to ask for more than one cost and count
item_cost = None # Let the user enter a number
item_count = None # Let the user enter a number
item_total = item_cost + item_count
for i in range(input_count):
item_cost = int(input(f"Enter cost of item {i+1}: "))
item_count = int(input(f"Enter quantity of item {i+1}: "))
item_total = item_cost * item_count
total += item_total

print(f"The total cost is: {total}")

print(total)
2 changes: 1 addition & 1 deletion day_01/02_control_flow/exercise/10_login_system_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
password_input = input("Please provide password: ")

# TODO: Notify user if password is valid or invalid
correct_password_given = None
correct_password_given = correct_password == password_input
print("Access Granted")
print("Access Denied")
8 changes: 5 additions & 3 deletions day_01/02_control_flow/exercise/10_login_system_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
password_input = input("Please provide password: ")

# TODO: Notify user if credentials are valid or invalid
correct_credentials = None
print("Access Granted")
print("Access Denied")
correct_credentials = (correct_username == username_input) * (correct_password == password_input)
if correct_credentials:
print("Access Granted")
else:
print("Access Denied")
8 changes: 5 additions & 3 deletions day_01/02_control_flow/exercise/10_login_system_v5.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
password_input = input("Please provide password: ")

# TODO: Notify user if credentials are valid or invalid
correct_credentials = None
print("Access Granted")
print("Access Denied")
correct_credentials = ((correct_username == username_input) * (correct_password == password_input)) or ((admin_username == username_input) * (admin_password == password_input))
if correct_credentials:
print("Access Granted")
else:
print("Access Denied")
19 changes: 19 additions & 0 deletions day_01/02_control_flow/exercise/11_traffic_lights.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,22 @@
# "green" -> print "Go"
# "yellow" -> print "Wait..."
# "red" -> print "Stop"

if color_input == "green":
print("Go")
elif color_input == "yellow":
print("Wait...")
elif color_input == "red":
print("Stop")


match color_input:
case "green":
print("Go")
case "yellow":
print("Wait...")
case "red":
print("Stop")



19 changes: 19 additions & 0 deletions day_01/02_control_flow/exercise/11_traffic_lights_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,22 @@
# "yellow" -> print "Wait..."
# "red" -> print "Stop"
# Everything else -> print "Malfunction"

if color_input == "green":
print("Go")
elif color_input == "yellow":
print("Wait...")
elif color_input == "red":
print("Stop")
else:
print("Malfunction")

match color_input:
case "green":
print("Go")
case "yellow":
print("Wait...")
case "red":
print("Stop")
case _:
print("Malfunction")
8 changes: 7 additions & 1 deletion day_01/02_control_flow/exercise/12_bookmarks_v2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# TODO: Define a list of your favorite websites
websites = []
websites = ["facebook.com", "instagram.com", "twitter.com", "linkedIn.com", "github.com"]

# TODO: Print the entire list of websites (one at a time)
for site in websites:
print(site)

numbers = [0, 1, 2]
for number in range(3):
print (number)
4 changes: 3 additions & 1 deletion day_01/02_control_flow/exercise/13_repetition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
message = "This is a very long message that's hard to type"

# TODO: Print the message eleven times
print(message)
print(message)
for x in range(11):
print(message)
4 changes: 3 additions & 1 deletion day_01/02_control_flow/exercise/14_counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
end = int(input("Enter number: "))

# TODO: Print the numbers 0 to end
print()
range_numbers = range(end + 1)
for number in range_numbers:
print(number)
Loading