From bec104245fe68a643477fb818a945316721b783e Mon Sep 17 00:00:00 2001 From: NilsForssen Date: Tue, 1 Feb 2022 10:16:08 +0100 Subject: [PATCH] latptop --- Laboration1/uppgift_1.txt | 23 --- Laboration1/uppgift_2.txt | 22 --- Laboration1/uppgift_3.txt | 21 --- __init__.py | 0 laboration1/__init__.py | 1 + laboration1/__pycache__/myTest.cpython-38.pyc | Bin 0 -> 2332 bytes {Laboration1 => laboration1}/del1.txt | 1 + .../uppgift_1.py => laboration1/myTest.py | 0 {Laboration1 => laboration1}/pythonskript.py | 0 laboration1/uppgift_1.py | 60 ++++++++ laboration1/uppgift_1.txt | 23 +++ laboration1/uppgift_1_test.py | 14 ++ {Laboration1 => laboration1}/uppgift_2.py | 0 laboration1/uppgift_2.txt | 22 +++ {Laboration1 => laboration1}/uppgift_3.py | 0 laboration1/uppgift_3.txt | 21 +++ laboration2/med.py | 17 +++ laboration2/uppgift_1.py | 44 ++++++ laboration2/uppgift_1.txt | 24 ++++ laboration2/uppgift_2.py | 131 ++++++++++++++++++ laboration2/uppgift_2.txt | 31 +++++ laboration2/uppgift_3.py | 70 ++++++++++ test.py | 23 --- test2.py | 3 - 24 files changed, 459 insertions(+), 92 deletions(-) delete mode 100644 Laboration1/uppgift_1.txt delete mode 100644 Laboration1/uppgift_2.txt delete mode 100644 Laboration1/uppgift_3.txt create mode 100644 __init__.py create mode 100644 laboration1/__init__.py create mode 100644 laboration1/__pycache__/myTest.cpython-38.pyc rename {Laboration1 => laboration1}/del1.txt (94%) rename Laboration1/uppgift_1.py => laboration1/myTest.py (100%) rename {Laboration1 => laboration1}/pythonskript.py (100%) create mode 100644 laboration1/uppgift_1.py create mode 100644 laboration1/uppgift_1.txt create mode 100644 laboration1/uppgift_1_test.py rename {Laboration1 => laboration1}/uppgift_2.py (100%) create mode 100644 laboration1/uppgift_2.txt rename {Laboration1 => laboration1}/uppgift_3.py (100%) create mode 100644 laboration1/uppgift_3.txt create mode 100755 laboration2/med.py create mode 100644 laboration2/uppgift_1.py create mode 100644 laboration2/uppgift_1.txt create mode 100644 laboration2/uppgift_2.py create mode 100644 laboration2/uppgift_2.txt create mode 100644 laboration2/uppgift_3.py delete mode 100644 test.py delete mode 100644 test2.py diff --git a/Laboration1/uppgift_1.txt b/Laboration1/uppgift_1.txt deleted file mode 100644 index 8d9bff4..0000000 --- a/Laboration1/uppgift_1.txt +++ /dev/null @@ -1,23 +0,0 @@ -UEsDBBQAAAAIAJuAM1QWfLPzhAEAACEEAAAaABwAbmlsZm8zNTktcHl1cHBnMV8xL29yaWcucHlV -VAkAA5Yo6GGWKOhhdXgLAAEEehxpWQQA4fUFjVPNjtsgEL77KZD3gr3ZRkmVw66Ux+h5NInHNpUN -CHC6fvsdB5KaNCvVF8T3NzCDX8QvazvVBrErCjVa44IYMfRF0VArHIXJaWjVhWT1UQj+IiTKBSuj -yjqlQya6IjJqqijCpgEfGO/8Y1RPv0vxKkqPOiVOniD0BBd0N/EFh4nEURzW1gjWDGY2dJ3EVC07 -0R1ch9zAmBFM2rL4Gp8flrk7cTdwNHXknjti3QdHOxgMz/U5dXegniHMlm7Mhs+97HMzZppqPZ+M -WDclI5LFT6fg8BzkFd1tYqf3ebHIibdEJqcdVICTGgaJo5l02Ag9jSdyYFqwZOyQV48isf1Xld3r -O1V6p8w2MFn5pJ/La/5xJjXIdU+iozF/9LceHoRxmanF3pHuiS/IEznT4NXkZaDRkkM2PqSsGe7S -z33FT1Uetu8pLgUsWX+T/zOOg963h4p/G45NY55Dj51x6OXnRswP5s+63rN65qWqa7nbLjbVCgCN -IwGI41GUACMqDVCmCaH3X1BLAwQUAAAACACbgDNUHcra+cgAAAAWAgAAJAAcAG5pbGZvMzU5LXB5 -dXBwZzFfMS9weXVwcGd0ZXN0MV8xLmxvZ1VUCQADlijoYZYo6GF1eAsAAQR6HGlZBADh9QV10U0K -wjAQBeB9TvHEjW7KpFr/dkK1SNWW2l5A0LagNWgV3HsGT6BX8AK5mK0uRJhklXzzwgyMaFYHfhBF -Ez/GXN9X8RhJGHqzaTyJUFeFqN+QlrRIjuBAHfSjSK0fSxpBEuOGuG2IdwzeNbhj8B7fts/HyWbj -1OG5y7PDMz8K9Xke8Dz8G1x8VrZKFosxwkDfll5VtslCSxJhvcn063Jqf1PuGfpxhDpudvk+L6p7 -CS9w/eqXC6WfCK9ldijOSqX5tqy7NQQg3lBLAwQUAAAACACbgDNUSbtDE3kAAACUAAAAGwAcAG5p -bGZvMzU5LXB5dXBwZzFfMS9pbmZvLnR4dFVUCQADlijoYZYo6GF1eAsAAQR6HGlZBADh9QVFzE0O -gyAQQOE9p+ACtAwCApcxOgyWFJX4s/D2lVW37yVfHE8KnCuplJAgwHOwQepgNLsO2p+15pK2zniW -ciGOH8Ivxadftc45nQO86s22Pc95HQtfojmuhaeE3kUT5WR6I8kpsp0jDdhP0iKmPyvq3SQY4N2Q -hv0AUEsBAh4DFAAAAAgAm4AzVBZ8s/OEAQAAIQQAABoAGAAAAAAAAQAAAKSBAAAAAG5pbGZvMzU5 -LXB5dXBwZzFfMS9vcmlnLnB5VVQFAAOWKOhhdXgLAAEEehxpWQQA4fUFUEsBAh4DFAAAAAgAm4Az -VB3K2vnIAAAAFgIAACQAGAAAAAAAAQAAAKSB2AEAAG5pbGZvMzU5LXB5dXBwZzFfMS9weXVwcGd0 -ZXN0MV8xLmxvZ1VUBQADlijoYXV4CwABBHocaVkEAOH1BVBLAQIeAxQAAAAIAJuAM1RJu0MTeQAA -AJQAAAAbABgAAAAAAAEAAACkgf4CAABuaWxmbzM1OS1weXVwcGcxXzEvaW5mby50eHRVVAUAA5Yo -6GF1eAsAAQR6HGlZBADh9QVQSwUGAAAAAAMAAwArAQAAzAMAAAAA \ No newline at end of file diff --git a/Laboration1/uppgift_2.txt b/Laboration1/uppgift_2.txt deleted file mode 100644 index 3423621..0000000 --- a/Laboration1/uppgift_2.txt +++ /dev/null @@ -1,22 +0,0 @@ -UEsDBBQAAAAIALuAM1S5y9gqSwEAAEEEAAAaABwAbmlsZ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l2tkDaKW1VCjRAb69Mt504th4vdZcal5exolc -KkP8cPxyuvrR2ljyPuhHO8WylrHMVGFKZjsm4J40slNEvUXMNtjAjnqKycSguu7PynbeEg76eSM3 -9gNQSwECHgMUAAAACAC7gDNUucvYKksBAABBBAAAGgAYAAAAAAABAAAApIEAAAAAbmlsZm8zNTkt -cHl1cHBnMV8yL29yaWcucHlVVAUAA9Io6GF1eAsAAQR6HGlZBADh9QVQSwECHgMUAAAACAC7gDNU -iGiPTMcAAAAKAgAAJAAYAAAAAAABAAAApIGfAQAAbmlsZm8zNTktcHl1cHBnMV8yL3B5dXBwZ3Rl -c3QxXzIubG9nVVQFAAPSKOhhdXgLAAEEehxpWQQA4fUFUEsBAh4DFAAAAAgAu4AzVNlGFWd5AAAA -lAAAABsAGAAAAAAAAQAAAKSBxAIAAG5pbGZvMzU5LXB5dXBwZzFfMi9pbmZvLnR4dFVUBQAD0ijo -YXV4CwABBHocaVkEAOH1BVBLBQYAAAAAAwADACsBAACSAwAAAAA= \ No newline at end of file diff --git a/Laboration1/uppgift_3.txt b/Laboration1/uppgift_3.txt deleted file mode 100644 index 52c3252..0000000 --- a/Laboration1/uppgift_3.txt +++ /dev/null @@ -1,21 +0,0 @@ -UEsDBBQAAAAIAOGAM1TnqvMgHAEAADUCAAAaABwAbmlsZm8zNTktcHl1cHBnMV8zL29yaWcucHlV -VAkAAxYp6GEWKehhdXgLAAEEehxpWQQA4fUFZVDBTsMwDL33K6xySbVqooPT7nwCp4GikLpdWJtE -jjvG3+MuG2wlUmIr7/n52Q/wGmPvOoanonBjDMRAxrdhLIoWO7DBW8Po5erE5HyfVI5NDTnZVNsC -5BDyRP7y2cDqCmehKaHmPerBefwgNAd1KYtCYlWSaaF583PYlNWt4D2U1Xr0SLOnGA44Bq+9GVFF -ws6dMImzqTtn99byYGu7D87+sSuxeo/8VudmnaPE+itQqxaCaZ3i4FhVu8f3zP0MzsuMidXRDNPS -QLkt1zPjCuYakgmOst5oLKb/LWjeY1TVdX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AAMWKehhdXgLAAEEehxpWQQA4fUFUEsFBgAAAAAD -AAMAKwEAAEADAAAAAA== \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/laboration1/__init__.py b/laboration1/__init__.py new file mode 100644 index 0000000..4c0ec1f --- /dev/null +++ b/laboration1/__init__.py @@ -0,0 +1 @@ +from .myTest import * diff --git a/laboration1/__pycache__/myTest.cpython-38.pyc b/laboration1/__pycache__/myTest.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..3ce808032128f9b3cbe0a8fbe7ca4ac6efa1e787 GIT binary patch literal 2332 zcmb7_OK%%h6vyY!dEd|H4lQH83obF@fHuw`1N z71()Nr8QWe)@cKFfi`Iiwn8^(8@5V2bQ5-wZqY9667A7#*k!sycVSoP9__=f(tUaW zyJptuomU0^nbe_Idw7lry+%vU(?j9na~vtsL;Q!{S)tJ^9d}R6na4%ko1Fgrs@_Q= zQ;)mhaq{7_kLw3Xs~?%zru9ZQOoOjEX|s+Z!`--De{pc|#nY$tP#-0%Z8wP@*Q3D; zliCk@gJG48?QT z!C%SJ++N4CW0tRY1y@(IMA{Jx3nW3-)UXJBkkq_J;FqMeV3TnWHv}}Ug^lZDqzcyX zx7l1O0AS9v4d0w1Y+ai$cN`}Aa)u9vo86ltYzx8V14oAV7eydaohn(Du~aVZT7gCH zW?2Vz(972VI65AJv+OG1@z_3@T`529A6eEd`)~@idl~8?wN1=Q!JVqzae<4M zVO^OQAZC>GW7}Mf`_Yl%AUO_tCh3Jac`Ioz?AqX{8;0*m2%{ags92WuYJKH1VZC3W z?{C>+)(XQ?q;02JYME}x(i?KwGJ>L@-+NzBu1*x+xju+*<3CL)&V(-oRYo96zKiQq zD5;-ZP8a1V?N<8J4!&rvM-?0A_i(Sxd#}IUd;QmQm(H1LR;`Ips2VLjr{~tO?y!kF z2BM;JTP94q{qzZ5ljSQ#_4Xh(5yZAM%3`Da$L})!d(INgNYnibZ_=5!#xUVdqIiZU zGxP)axf*_>uq6Ktl$M;g5yHkOgmV$8jRWJ)kq%gH_5Dx{X4kmV8`zF+<0F`Ugr_s~ zBltr<2qN8$gP^wIme76wSlR;1=fib%*KS#wAxpnvX(=q5on;5I> len(s2): + s1, s2 = s2, s1 + distances = range(len(s1) + 1) + for index2, char2 in enumerate(s2): + new_distances = [index2+1] + for index1, char1 in enumerate(s1): + if char1 == char2: + new_distances.append(distances[index1]) + else: + new_distances.append(1 + min((distances[index1], + distances[index1+1], + new_distances[-1]))) + distances = new_distances + return distances[-1] diff --git a/laboration2/uppgift_1.py b/laboration2/uppgift_1.py new file mode 100644 index 0000000..a4f7df3 --- /dev/null +++ b/laboration2/uppgift_1.py @@ -0,0 +1,44 @@ +# Uppgift 1 + +def greeting(name): + return "Hej " + name + ("!" if name[0] != "M" else ", visste du att M är min favoritbokstav!") + +def is_this_a_long_list(values): + return len(values) > 5 + +def get_grade(score): + if score > 80: grade = "VG" + elif score >=50: grade = "G" + else: grade = "U" + return grade + +def days_in_month(name_of_month): + if name_of_month == "januari": days = 31 + elif name_of_month == "februari": days = 28 + elif name_of_month == "mars": days = 31 + elif name_of_month == "april": days = 30 + elif name_of_month == "maj": days = 31 + elif name_of_month == "juni": days = 30 + elif name_of_month == "juli": days = 31 + elif name_of_month == "augusti": days = 31 + elif name_of_month == "september": days = 30 + elif name_of_month == "oktober": days = 31 + elif name_of_month == "november": days = 30 + elif name_of_month == "december": days = 31 + else: days = None + return days + +def odd(value): + return value % 2 + +def get_integer_description(value): + if value % 2 and value > 0: desc = 1 + elif value % 2 and value < 0: desc = -1 + elif not value % 2 and value > 0: desc = 2 + elif not value % 2 and value < 0: desc = -2 + else: desc = 0 + return desc + +def appraisal_factor(rare, good_condition): + return 1 + 0.25 * (rare or -1) + 0.5*(good_condition or -1) + diff --git a/laboration2/uppgift_1.txt b/laboration2/uppgift_1.txt new file mode 100644 index 0000000..e1453d3 --- /dev/null +++ b/laboration2/uppgift_1.txt @@ -0,0 +1,24 @@ +UEsDB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CwBQSwMEFAAAAAgAjWk6VGg1mCJ4AAAAlAAAABsAHABuaWxmbzM1OS1weXVwcGcyXzEvaW5mby50 +eHRVVAkAA6k68WGpOvFhdXgLAAEEehxpWQQA4fUFRcxNDoMgEEDhPaeYC9AyA1jkMgZxsKSoxJ+F +t1dX3b6XfEPY2QOQIpIKJTWA2iN5suLYeL3XnEtatG1FyoUhfjn+eLj7UeuY097hq55iWfOY51Bg +Gux2TKCVMvjpg4nGusTchkDErml7hc5h/2dlPR+JOnw/yINdUEsBAh4DFAAAAAgAjWk6VHww5jbH +AQAAQwUAABoAGAAAAAAAAQAAAKSBAAAAAG5pbGZvMzU5LXB5dXBwZzJfMS9vcmlnLnB5VVQFAAOp +OvFhdXgLAAEEehxpWQQA4fUFUEsBAh4DFAAAAAgAjWk6VD0JczynAAAAKQEAACQAGAAAAAAAAQAA +AKSBGwIAAG5pbGZvMzU5LXB5dXBwZzJfMS9weXVwcGd0ZXN0Ml8xLmxvZ1VUBQADqTrxYXV4CwAB +BHocaVkEAOH1BVBLAQIeAxQAAAAIAI1pOlRoNZgieAAAAJQAAAAbABgAAAAAAAEAAACkgSADAABu +aWxmbzM1OS1weXVwcGcyXzEvaW5mby50eHRVVAUAA6k68WF1eAsAAQR6HGlZBADh9QVQSwUGAAAA +AAMAAwArAQAA7QMAAAAA \ No newline at end of file diff --git a/laboration2/uppgift_2.py b/laboration2/uppgift_2.py new file mode 100644 index 0000000..dd1507f --- /dev/null +++ b/laboration2/uppgift_2.py @@ -0,0 +1,131 @@ +# Uppgift 2 + +def create_ten_list_while(): + i = 0 + myList = [] + while i < 11: + myList.append(i) + i += 1 + return myList + +def create_ten_list_for(): + # Jag vill argumentera att list-comprehension använder sig av en for-loop + return [i for i in range(0, 11)] + +def create_zero_to_number_list_while(number): + i = 0 + myList = [] + while i < number + 1: + myList.append(i) + i += 1 + return myList + +def create_zero_to_number_list_for(number): + return [i for i in range(0, number + 1)] + +def create_number_to_number_list_while(start_number, end_number): + i = start_number + myList = [] + while i < end_number + 1: + myList.append(i) + i += 1 + return myList + +def create_number_to_number_list_for(start_number, end_number): + return [i for i in range(start_number, end_number + 1)] + +def get_max_while(integer_list): + myMax = integer_list[0] + i = 0 + while i < len(integer_list[1:]): + if integer_list[i + 1] > myMax: myMax = integer_list[i + 1] + i += 1 + return myMax + +def get_max_for(integer_list): + myMax = integer_list[0] + for elm in integer_list[1:]: + if elm > myMax: myMax = elm + return myMax + +def get_min(integer_list): + myMin = integer_list[0] + for elm in integer_list[1:]: + if elm < myMin: myMin = elm + return myMin + +def word_in_list_while(words, word): + i = 0 + while i < len(words): + if words[i] == word: break + i += 1 + else: return False + return True + +def word_in_list_for(words, word): + for elm in words: + if elm == word: + break + else: return False + return True + +def count_integers_while(value_list): + count = 0 + i = 0 + while i < len(value_list): + if isinstance(value_list[i], int): count += 1 + i += 1 + return count + +def count_integers_for(value_list): + count = 0 + for elm in value_list: + if isinstance(elm, int): count += 1 + return count + +def average_while(values): + i = 0 + tot = 0 + while i < len(values): + tot += values[i] + i += 1 + return tot/len(values) + +def average_for(values): + tot = 0 + for elm in values: + tot += elm + return tot/len(values) + +def population(pop_a, rate_a, pop_b, rate_b): + if pop_a == pop_b: return 0 + + lower_pop = pop_a if pop_a < pop_b else pop_b + higher_pop = pop_a if lower_pop is pop_b else pop_b + higher_rate = rate_a if rate_a > rate_b else rate_b + lower_rate = rate_a if higher_rate is rate_b else rate_b + + if (lower_pop is pop_a and higher_rate is rate_b) or (lower_pop is pop_b and higher_rate is rate_a): + return -1 + + years = 0 + while lower_pop < higher_pop: + print(lower_pop) + print(higher_pop) + lower_pop += lower_pop*(higher_rate/100) + higher_pop += higher_pop*(lower_rate/100) + years += 1 + + return years + +def birthday(n): + prod = 1 + for i in range(0,n): + prod *= (365-i)/365 + return 1 - prod + +def sum_of_ints(value_list): + tot = 0 + for elm in value_list: + if isinstance(elm, int): tot += elm + return tot \ No newline at end of file diff --git a/laboration2/uppgift_2.txt b/laboration2/uppgift_2.txt new file mode 100644 index 0000000..3f08920 --- /dev/null +++ b/laboration2/uppgift_2.txt @@ -0,0 +1,31 @@ +UEsDBBQAAAAIAPVxOlRPedNKJQMAADoMAAAaABwAbmlsZm8zNTktcHl1cHBnMl8yL29yaWcucHlV +VAkAA31J8WFcSfFhdXgLAAEEehxpWQQA4fUFrVbLctowFN3zFXcmGzuBBtpJFwxk2UWn3bUrhvEI +LIymtuyRZRL6Pf2T/livHrZky5BkGjbocc695x5dCW7gZ1Vl7CDh42SS0gPsBSWSJpLyJGe1TJ6O +LKdRvJwAfhisYQ56WJy/4TbON1s91zgErGCxMGCH+kCqivI0YnG3weBuDQsTSlDZCG6x4yoOpWg1 +3MBXksGJ5TkQkTUF5ZIKAkRKUNDZviwqQY+U16zkQPjp7x+eUgE1y4CcgHLAYLO8LCs/+YapZZTF +OAjCMxrNp1hJvO3p+U1Fmcgy4U2xo8I3yKy8xSbDgDt4P7vG5CnneuKuFew0DQq3EUdLryUR0q5P +0d80CczwIS/Y4vjvas14AcqcF+RftOsSz3cvozIpyLM1imGnZja1jV6cv5NntMHf2sy3wy5y9uSU +9+JsFstt7Fxih34optRs4dEkWo7nM6CBoX0/kdWvSDn3xnqUfzQvlIPDCnoFKEwgGBevKWL8ghpM +9v9qVibSsgsYqmHcqHkqRZqw3tupluqp3gnfh/7Jamj/OPXShm1hvdbjJeywo3+NnRbNa7psNX0h +OPNF/hANHdGoDjJU6LmjNwNLWjXduvo4Za+Vsi8bLhN7ALU17ETyhvrnqFHKs+vuBbz2RtSM423l +ez80WjpVJx8vbfjOxvE7oEGjopWDL0j27HTISxoReEFZKIWc8Lcvo75xtd9keiRLp2TEMb/hFBTT +mXW06IohCL33YvT1dJ60wa0GGLWjDgQMLthorqqsmpxI/JWPcJiQKT7M+NLjt5ru7HTX2qEJCVGd +q/e79pxPNCAvn/ANwC1YW2RHWRmG7moz1Iwjy44hxcVh9VWekodEI1ox7ejRCjc0M/YUBjQ/HKYc +IbcGRIE2/N/E0/EIMeAphYzdR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B5dXBwZzJfMi9weXVwcGd0ZXN0Ml8yLmxvZ1VUBQADfUnxYXV4CwABBHocaVkEAOH1 +BVBLAQIeAxQAAAAIAPVxOlRDWsGVeAAAAJQAAAAbABgAAAAAAAEAAACkgaYEAABuaWxmbzM1OS1w +eXVwcGcyXzIvaW5mby50eHRVVAUAA31J8WF1eAsAAQR6HGlZBADh9QVQSwUGAAAAAAMAAwArAQAA +cwUAAAAA \ No newline at end of file diff --git a/laboration2/uppgift_3.py b/laboration2/uppgift_3.py new file mode 100644 index 0000000..a108221 --- /dev/null +++ b/laboration2/uppgift_3.py @@ -0,0 +1,70 @@ +# Uppgift 3 + +def replace_periods_with_newlines(string_value): + s = "" + for char in string_value: + if char == '.': s += '\n' + else: s += char + return s + +def replace_char_in_string(original_string, search_character, replacement): + s = "" + for char in original_string: + if char == search_character: s += replacement + else: s += char + return s + +def reverse_string_while(string_value): + i = len(string_value) - 1 + s = "" + while i > -1: + s += string_value[i] + return s + +def reverse_string_for(string_value): + s = "" + for char in string_value: + s = char + s + +def get_five_first(value_list): + myList = [] + for elm in value_list: + myList.append(elm) + if len(myList) == 5: break + return myList + +def get_nfirst(value_list, n): + myList = [] + for elm in value_list: + myList.append(elm) + if len(myList) == n: break + return myList + +def get_all_less_than(values, cutoff): + return [elm for elm in values if elm < cutoff] + +def get_all_even(values): + return [elm for elm in values if not elm % 2] + +def get_all_divisible(values, divisor): + return [elm for elm in values if not elm % divisor] + +def multiply_for_each(values, multiplier): + for i, elm in enumerate(values): + values[i] = elm * multiplier + return values + +def insert_at_asc_place(values, new_value): + mid = len(values) // 2 + newList = values.copy() + idx = mid + while True: + idx = idx - mid if new_value < newList[mid] else idx + mid + newList = newList[slice(0, mid, 1) if new_value < newList[mid] else slice(mid, len(values), 1)] + mid = len(newList) // 2 + if mid == 0: + values.insert(idx, newList[0]) + break + return values + +print(insert_at_asc_place([1,2,3,4,6,7], 2)) \ No newline at end of file diff --git a/test.py b/test.py deleted file mode 100644 index 6aa46c9..0000000 --- a/test.py +++ /dev/null @@ -1,23 +0,0 @@ - -def binary_search(key: int, srt_list: list, carry=0): - length = len(srt_list) - idx = length // 2 - - if key > srt_list[idx]: - return binary_search(key, srt_list[idx:], carry=carry+idx) - elif key < srt_list[idx]: - return binary_search(key, srt_list[:idx], carry=carry) - else: - return carry + idx - - -def this(keuy: int): - - return keuy - - -if __name__ == "__main__": - myList = [12, 45, 345, 345, 234, 13, 1, 5] - myList.sort() - print(myList) - print(binary_search(345, myList)) diff --git a/test2.py b/test2.py deleted file mode 100644 index 471194c..0000000 --- a/test2.py +++ /dev/null @@ -1,3 +0,0 @@ -from uppgift_1 import subtract - -print(subtract(2,4)) -- 2.30.2