Preparing git repo for final project

This commit is contained in:
2023-07-09 11:19:26 +02:00
parent 6a38966eef
commit 63d06d6b35
67 changed files with 1587 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
c = 300000000
def compute_energy():
mass = None
while not isinstance(mass, int):
input_string = input("Enter a mass:\t\t")
try:
mass = int(input_string)
except (ValueError, TypeError):
mass = None
print(mass*(c**2))
if __name__ == "__main__":
compute_energy()

View File

@@ -0,0 +1,9 @@
def replace_emoticons_with_emojis():
input_string = input("Say something quickly and I will repeat it slowly!\t\t")
for emoticon, emoji in {':)': '🙂', ':(': '🙁'}.items():
input_string = input_string.replace(emoticon, emoji)
print(input_string)
if __name__ == "__main__":
replace_emoticons_with_emojis()

View File

@@ -0,0 +1,7 @@
def prompt_user_and_echo_lowercase():
input_string = input("Shout me something and I will repeat it with indoor voice!\t\t")
print(input_string.lower())
if __name__ == "__main__":
prompt_user_and_echo_lowercase()

View File

@@ -0,0 +1,7 @@
def prompt_user_and_echo_lowercase():
input_string = input("Say something quickly and I will repeat it slowly!\t\t")
print(input_string.replace(' ', '...'))
if __name__ == "__main__":
prompt_user_and_echo_lowercase()

17
problems/pset0/tip/tip.py Normal file
View File

@@ -0,0 +1,17 @@
def main():
dollars = dollars_to_float(input("How much was the meal? "))
percent = percent_to_float(input("What percentage would you like to tip? "))
tip = dollars * percent
print(f"Leave ${tip:.2f}")
def dollars_to_float(d):
return float(d[1:])
def percent_to_float(p):
return float(p[:-1])/100
if __name__ == "__main__":
main()