From 4b0e8f2824203cb73e5ff7a4b83fcdde19fd8f8b Mon Sep 17 00:00:00 2001 From: Timmy Elf Date: Thu, 15 Sep 2022 11:39:44 +0200 Subject: [PATCH 1/4] Added exercises and moving items to GitHub to work on from another computer. --- ...3_exercise_2_datastrukturer_grupparbete.py | 159 ++++++++++++++++++ lesson_5/exercises/exercise_1.py | 26 +++ lesson_5/exercises/exercise_2.py | 19 +++ lesson_5/exercises/exercise_3.py | 8 + lesson_5/exercises/exercise_4.py | 16 ++ lesson_5/exercises/exercise_5.py | 0 ...a_\303\266vning_studieportal_or_github.py" | 20 +++ lesson_8/exercises/exercise_1.py | 0 lesson_8/exercises/exercise_2.py | 0 lesson_8/exercises/exercise_3.py | 0 lesson_8/exercises/exercise_4.py | 0 lesson_8/exercises/exercise_5.py | 0 12 files changed, 248 insertions(+) create mode 100644 lesson_3/examples/lesson_3_exercise_2_datastrukturer_grupparbete.py create mode 100644 lesson_5/exercises/exercise_1.py create mode 100644 lesson_5/exercises/exercise_2.py create mode 100644 lesson_5/exercises/exercise_3.py create mode 100644 lesson_5/exercises/exercise_4.py create mode 100644 lesson_5/exercises/exercise_5.py create mode 100644 "lesson_5/exercises/extra_\303\266vning_studieportal_or_github.py" create mode 100644 lesson_8/exercises/exercise_1.py create mode 100644 lesson_8/exercises/exercise_2.py create mode 100644 lesson_8/exercises/exercise_3.py create mode 100644 lesson_8/exercises/exercise_4.py create mode 100644 lesson_8/exercises/exercise_5.py diff --git a/lesson_3/examples/lesson_3_exercise_2_datastrukturer_grupparbete.py b/lesson_3/examples/lesson_3_exercise_2_datastrukturer_grupparbete.py new file mode 100644 index 00000000..14108f23 --- /dev/null +++ b/lesson_3/examples/lesson_3_exercise_2_datastrukturer_grupparbete.py @@ -0,0 +1,159 @@ +from http.client import CannotSendRequest + + +X = 1 +Y = 4 +addresses = {"Adam":"Ormvägen 5", + "Bella":"Klockgatan 1", + "Cornelia":"Vikingagatan 3"} +cars = ["Volvo", "Opel", "BMW"] +numbers1 = {1,2,3,X,6} +numbers2 = {Y,2,3,4,7} + +#A1. X = Int +# Y = Int + +#2. Dictionary + +#3. +print (addresses["Bella"]) + +#4. Daniel blir tillagd i dictionary +addresses["Daniel"]="Prinsgränd 2" +print (addresses["Daniel"]) + +#5 +l=len (addresses) +print (l) + +#5.1 +name=sorted(addresses)[-1] +print(addresses[name]) + +#5.2 +addresses_reversed = {v:k for k, v in addresses.items()} +address = sorted(addresses_reversed)[0] +print(addresses_reversed[address]) + +#6 list + +#7. Opel + +#8. Error + +#9. BMW +cars.sort() +print(cars[0]) + +#10 +cars_2=cars +cars_3=[] + +#10.1 + +cars_3=[] +cars_3.extend(cars) +cars.append("Saab") +print(cars) +print(cars_2) +print(cars_3) + +#10.2 + +cars.extend(cars) +cars.sort(reverse=True) +print (cars) + +#10.3 + +unique_cars=(list(set(cars))) +print (unique_cars) + +#11. +print(type(numbers1)) #Set + +#12. +print(numbers1, numbers2) + +#13. +print(numbers1.intersection(numbers2)) + +#14. +print(numbers1.union(numbers2)) + +#15. +print(numbers1.symmetric_difference(numbers2)) + +#B. +names = [] +ages = [] +sizes = [] +res = input("Please enter name for person 1 ") +names.append(res.title()) +res = input("Please enter age for person 1 ") +ages.append(int(res)) +res = input("Please enter shoe size for person 1 ") +sizes.append(int(res)) +res = input("Please enter name for person 2 ") +names.append(res.title()) +res = input("Please enter age for person 2 ") +ages.append(int(res)) +res = input("Please enter shoe size for person 2 ") +sizes.append(int(res)) +res = input("Please enter name for person 3 ") +names.append(res.title()) +res = input("Please enter age for person 3 ") +ages.append(int(res)) +res = input("Please enter shoe size for person 3 ") +sizes.append(int(res)) + +age_to_name = { + str(ages[0]): names[0], + str(ages[1]): names[1], + str(ages[2]): names[2] + } +age_to_size = { + str(ages[0]): str(sizes[0]), + str(ages[1]): str(sizes[1]), + str(ages[2]): str(sizes[2]) + } +name_to_size = { + names[0]: str(sizes[0]), + names[1]: str(sizes[1]), + names[2]: str(sizes[2]) + } +eldest_age = str(sorted(ages)[-1]) +eldest_name = age_to_name[eldest_age] +eldest_size = age_to_size[eldest_age] + +size_to_age = {v: k for k, v in age_to_size.items()} +biggest_size = str(sorted(sizes)[1]) +biggest_age = size_to_age[biggest_size] +biggest_name = age_to_name[biggest_age] + +name_to_age = {v: k for k, v in age_to_name.items()} +size_to_name = {v: k for k, v in age_to_name.items()} + +commands = { + "name": [name_to_age, name_to_size], + "age": [age_to_name, age_to_size], + "size": [size_to_age, size_to_name] + } + +present_order = { + "name": ["age", "size"], + "age": ["name", "size"], + "size": ["age", "name"] + } + +print(f'The oldest person is {eldest_name} who has shoe size {eldest_size}') +print(f'The person with median shoe size is {biggest_name} who is {biggest_age} years old') +res = input('Please enter search value, name, age or size followed by value: ') +the_input = res.split() +my_key = the_input[0] +my_value = the_input[1] + +print('Found Person') +print(f'{my_key}: {my_value}') +print(f'{present_order[my_key][0]}: {commands[my_key][0][my_value]}') +print(f'{present_order[my_key][1]}: {commands[my_key][1][my_value]}') diff --git a/lesson_5/exercises/exercise_1.py b/lesson_5/exercises/exercise_1.py new file mode 100644 index 00000000..99959c3d --- /dev/null +++ b/lesson_5/exercises/exercise_1.py @@ -0,0 +1,26 @@ +#Basic usage + +from os import terminal_size + + +first_name = "Bengt" + +last_name = "Bengtsson" + +tele_number = "070123456789" + +print(first_name, last_name, tele_number) + +full_name = (first_name + " " + last_name) + +print(len(full_name), len(first_name), len(last_name)) + +print(first_name, last_name,"\n",tele_number) + +print(full_name + " " + tele_number) # i. + +print(f'{full_name} {tele_number}') # ii. + +print("{}".format(full_name), "{}".format(tele_number)) # iii. + +print("%s" % full_name, tele_number) # iv. \ No newline at end of file diff --git a/lesson_5/exercises/exercise_2.py b/lesson_5/exercises/exercise_2.py new file mode 100644 index 00000000..b0eeb611 --- /dev/null +++ b/lesson_5/exercises/exercise_2.py @@ -0,0 +1,19 @@ +# Slice + +first_name = "Bengt" + +last_name = "Bengtsson" + +tele_number = "070123456789" + +full_name = (first_name + " " + last_name) + +print(full_name[0:5]) # 1. + +print(full_name[1:-1]) # 2. + +print(str.upper(full_name[::2])) # 3. + +print(full_name[::-1]) # 4. + +print(full_name[6:-9]) # 5. \ No newline at end of file diff --git a/lesson_5/exercises/exercise_3.py b/lesson_5/exercises/exercise_3.py new file mode 100644 index 00000000..4a89407b --- /dev/null +++ b/lesson_5/exercises/exercise_3.py @@ -0,0 +1,8 @@ +# Unicode + +car_cost = int(input("Your new car cost:" + "\U000020AC" "")) # 1. + +if(car_cost > 10000): + print("\U0001F44D") +else: + print("\U0001F44E") \ No newline at end of file diff --git a/lesson_5/exercises/exercise_4.py b/lesson_5/exercises/exercise_4.py new file mode 100644 index 00000000..bea3993f --- /dev/null +++ b/lesson_5/exercises/exercise_4.py @@ -0,0 +1,16 @@ +#Extra + +current_salary = 10000 + +print("Your current salary is 10000" + "\U000020AC") # 1. + +more_money = int(input("How much more do you want?")) # 2. + +boss_calculation = (more_money/current_salary) + +print(boss_calculation) + +if(more_money > 0): + print("No ""\U0001F90C") +else: + (print("Try again, how much more do you want? ")) diff --git a/lesson_5/exercises/exercise_5.py b/lesson_5/exercises/exercise_5.py new file mode 100644 index 00000000..e69de29b diff --git "a/lesson_5/exercises/extra_\303\266vning_studieportal_or_github.py" "b/lesson_5/exercises/extra_\303\266vning_studieportal_or_github.py" new file mode 100644 index 00000000..ce1e3418 --- /dev/null +++ "b/lesson_5/exercises/extra_\303\266vning_studieportal_or_github.py" @@ -0,0 +1,20 @@ +# Jag tYcker om äGg. +# JAG tYCKER iNTE oM äGg. + +from tracemalloc import start + +words = start.split() + +words[0] = words[0].swapcase() + +words[1] = words[1].capitalize().swapcase() + +words.insert(2, "inte".capitalize().swapcase()) + +words[3] = words[3].capitalize().swapcase() + +words[4] = "SPAM" + +print(" ".join(words)) + +print(words) \ No newline at end of file diff --git a/lesson_8/exercises/exercise_1.py b/lesson_8/exercises/exercise_1.py new file mode 100644 index 00000000..e69de29b diff --git a/lesson_8/exercises/exercise_2.py b/lesson_8/exercises/exercise_2.py new file mode 100644 index 00000000..e69de29b diff --git a/lesson_8/exercises/exercise_3.py b/lesson_8/exercises/exercise_3.py new file mode 100644 index 00000000..e69de29b diff --git a/lesson_8/exercises/exercise_4.py b/lesson_8/exercises/exercise_4.py new file mode 100644 index 00000000..e69de29b diff --git a/lesson_8/exercises/exercise_5.py b/lesson_8/exercises/exercise_5.py new file mode 100644 index 00000000..e69de29b From fbb7c4ab9a86c85505b0500dfa2abc2186e8c323 Mon Sep 17 00:00:00 2001 From: Timmy Elf Date: Sun, 18 Sep 2022 22:56:50 +0200 Subject: [PATCH 2/4] Updated exercises --- lesson_8/exercises/exercise_1.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lesson_8/exercises/exercise_1.py b/lesson_8/exercises/exercise_1.py index e69de29b..01370b57 100644 --- a/lesson_8/exercises/exercise_1.py +++ b/lesson_8/exercises/exercise_1.py @@ -0,0 +1,3 @@ +# Raise + +# 1. From 49382c0ffc86df69fbd9b9e6a8eda10cfd3f6802 Mon Sep 17 00:00:00 2001 From: Timmy Elf Date: Tue, 20 Sep 2022 14:31:07 +0200 Subject: [PATCH 3/4] best From 4f663622acc6aed22b595cfd778b37862b1fc726 Mon Sep 17 00:00:00 2001 From: Timmy Elf Date: Tue, 20 Sep 2022 14:31:34 +0200 Subject: [PATCH 4/4] best