Last active
March 31, 2024 13:09
-
-
Save under-script/90e02f28dff5572f119ec55ba48debcb to your computer and use it in GitHub Desktop.
Day 2 - Beginner - Understanding Data Types and How to Manipulate Strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Data Types | |
#String | |
"Hello"[4] | |
print("123" + "345") | |
#Integer | |
print(123 + 345) | |
123_456_789 | |
#Float | |
3.14159 | |
#Boolean | |
True | |
False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# num_char = len(input("What is your name?")) | |
# new_num_char = str(num_char) | |
# print("Your name contains " + new_num_char + "charackters") | |
a = float(123) | |
print(type(a)) | |
print(70 + float("100.5")) | |
print(str(70) + str(100)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
two_digit_number = input() | |
# π¨ Don't change the code above π | |
#################################### | |
# Write your code below this line π | |
first_digit = int(two_digit_number[0]) | |
second_digit = int(two_digit_number[1]) | |
#Add the integers together | |
two_digit_numbers = first_digit + second_digit | |
print(two_digit_numbers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 3 + 5 | |
# 7 - 4 | |
# 3 * 2 | |
# 6 / 3 | |
# 2 ** 3 | |
#PEMDAS | |
# ( ) | |
# ** | |
# * / | |
# + - | |
print(3 * 3 + 3 / 3 - 3) | |
print(3 * (3 + 3) / 3 - 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
height = input() | |
weight = input() | |
# Your code below this line π | |
weight_as_int = int(weight) | |
height_as_float = float(height) | |
# Using the exponent operator ** | |
bmi = weight_as_int / height_as_float ** 2 | |
# or using multiplication and PEMDAS | |
bmi = weight_as_int / (height_as_float * height_as_float) | |
bmi_as_int = int(bmi) | |
print(bmi_as_int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
score = 0 | |
height = 1.8 | |
is_winning = True | |
#f-String | |
print(f"Your score is {score}, your height is {height}, and that yo're winning is {is_winning}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
age = input() | |
# π¨ Don't change the code above π | |
# Write your code below this line π | |
years = 90 - int(age) | |
weeks = years * 52 | |
print(f"You have {weeks} weeks left.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#If the bill was $150.00, split between 5 people, with 12% tip. | |
#Each person should pay (150.00 / 5) * 1.12 = 33.6 | |
#Round the result to 2 decimal places. | |
print("Welcome to the tip calculator!") | |
bill = float(input("What was the total bill? $")) | |
tip = int(input("How much tip would you like to give? 10, 12, or 15? ")) | |
people = int(input("How many people to split the bill?")) | |
tip_as_percent = tip / 100 | |
total_tip_amount = bill * tip_as_percent | |
total_bill = bill + total_tip_amount | |
bill_per_person = total_bill / people | |
final_amount = round(bill_per_person, 2) | |
# FAQ: How to round to 2 decimal places? | |
# Find the answer in the Q&A here: https://www.udemy.com/course/100-days-of-code/learn/lecture/17965132#questions/13315048 | |
print(f"Each person should pay: ${final_amount}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment