From 3f92bc616320104d51764505c44362c0e5c3ad69 Mon Sep 17 00:00:00 2001 From: newt Date: Wed, 9 Oct 2024 18:02:47 +0100 Subject: [PATCH] feat(hmwk): fundementals part 1 homework --- .../a-level/homework/fundementals/einstein.py | 11 ++++++++ .../homework/fundementals/indoor voice.py | 3 +++ .../homework/fundementals/making faces.py | 11 ++++++++ .../homework/fundementals/playback speed.py | 3 +++ .../homework/fundementals/tip calculator.py | 25 +++++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 school/a-level/homework/fundementals/einstein.py create mode 100644 school/a-level/homework/fundementals/indoor voice.py create mode 100644 school/a-level/homework/fundementals/making faces.py create mode 100644 school/a-level/homework/fundementals/playback speed.py create mode 100644 school/a-level/homework/fundementals/tip calculator.py diff --git a/school/a-level/homework/fundementals/einstein.py b/school/a-level/homework/fundementals/einstein.py new file mode 100644 index 0000000..2423dad --- /dev/null +++ b/school/a-level/homework/fundementals/einstein.py @@ -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') diff --git a/school/a-level/homework/fundementals/indoor voice.py b/school/a-level/homework/fundementals/indoor voice.py new file mode 100644 index 0000000..b1b4fb5 --- /dev/null +++ b/school/a-level/homework/fundementals/indoor voice.py @@ -0,0 +1,3 @@ +text = input('Please enter some text: ') +text = text.lower() +print(text) diff --git a/school/a-level/homework/fundementals/making faces.py b/school/a-level/homework/fundementals/making faces.py new file mode 100644 index 0000000..49738bf --- /dev/null +++ b/school/a-level/homework/fundementals/making faces.py @@ -0,0 +1,11 @@ +mapping = { + ':)': '🙂', + ':(': '🙁' +} + +text = input('Please enter some text: ') + +for emoticon in mapping.keys(): + text = text.replace(emoticon, mapping[emoticon]) + +print(text) diff --git a/school/a-level/homework/fundementals/playback speed.py b/school/a-level/homework/fundementals/playback speed.py new file mode 100644 index 0000000..c36fa9a --- /dev/null +++ b/school/a-level/homework/fundementals/playback speed.py @@ -0,0 +1,3 @@ +text = input('Please enter some text: ') +text = text.replace(' ', '...') +print(text) diff --git a/school/a-level/homework/fundementals/tip calculator.py b/school/a-level/homework/fundementals/tip calculator.py new file mode 100644 index 0000000..7b5bac8 --- /dev/null +++ b/school/a-level/homework/fundementals/tip calculator.py @@ -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}!')