Preparing git repo for final project
This commit is contained in:
16
problems/pset0/einstein/einstein.py
Normal file
16
problems/pset0/einstein/einstein.py
Normal 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()
|
9
problems/pset0/faces/faces.py
Normal file
9
problems/pset0/faces/faces.py
Normal 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()
|
7
problems/pset0/indoor/indoor.py
Normal file
7
problems/pset0/indoor/indoor.py
Normal 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()
|
7
problems/pset0/playback/playback.py
Normal file
7
problems/pset0/playback/playback.py
Normal 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
17
problems/pset0/tip/tip.py
Normal 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()
|
Reference in New Issue
Block a user