feat(hmwk): fundementals part 1 homework

This commit is contained in:
newt 2024-10-09 18:02:47 +01:00
parent 72f3bc757f
commit 3f92bc6163
5 changed files with 53 additions and 0 deletions

View file

@ -0,0 +1,11 @@
c = 299792458
while True:
try:
m = int(input('Please enter an integer mass in kg: '))
break
except ValueError:
print('Please ensure that your input was an integer!')
e = m * (c ** 2)
print(f'e = {e:,}J')

View file

@ -0,0 +1,3 @@
text = input('Please enter some text: ')
text = text.lower()
print(text)

View file

@ -0,0 +1,11 @@
mapping = {
':)': '🙂',
':(': '🙁'
}
text = input('Please enter some text: ')
for emoticon in mapping.keys():
text = text.replace(emoticon, mapping[emoticon])
print(text)

View file

@ -0,0 +1,3 @@
text = input('Please enter some text: ')
text = text.replace(' ', '...')
print(text)

View file

@ -0,0 +1,25 @@
while True:
try:
pounds = input('How much was the meal? ')
pounds = pounds.split('£')
pounds = pounds[len(pounds) - 1]
pounds = float(pounds)
break
except ValueError:
print('Please ensure that you input a valid amount of money!')
while True:
try:
percentage = input('What percentage would you like to tip? ')
percentage = percentage.split('%')[0]
percentage = float(percentage) / 100
break
except ValueError:
print('Please ensure that you enter a valid percentage!')
tip = round(pounds * percentage, 2)
print(f'You should tip £{tip}!')