














Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!















def my_function(n, a, b, k): max = 0 for y in range (3, n, 3): for x in range(a+1,b): if x-y >= k: if max < x+y: max = x + y return max print(my_function(20,1,21,12))
def my_function(n): mysum= 0 exponent = 0 while mysum <= n: exponent += 1 mysum = 1 + 10**exponent return exponent print(my_function(250))
def my_function(x, y, s): new_s = "" if x>0: if x == 1: new_s = s else: new_s = (s + (y"-"))(x-1) + s return new_s print(my_function(4,6,"T"))
return - print(find([1,4,6,47,9], 4))
def insert_list(list, i, v): for x in range(len(list)): if x == i : list[x] = v return list print (insert_list([1,2,3,4,5], 2, 14))
l[x-1] = x** return l print(square_list([1,2,3,4,5]))
def bitonic(lst): maximum = max(lst) index = lst.index(maximum) increasing = 0 decreasing = 0 for x in range(index): if lst[x] < lst[x+1]: increasing = 0 else: increasing = 1 for y in range(index+1, len(lst)): if lst[y] < lst[y-1]: decreasing = 0 else: decreasing = 1 if increasing == 0 and decreasing == 0: return True else: return False print(bitonic([-3,9,11,20,17,5,1]))
for x in range(index): if l2[x] < l2[x+1]: increasing = 0 else: increasing = 1 for y in range(index+1, len(lst)): if l2[y] < l2[y-1]: decreasing = 0 else: decreasing = 1 if increasing == 0 and decreasing == 0: return True else: return False print(bitonic([-3,9,11,20,17,5,1], -1))
d = {"monkey":12, "alessia": 3, "giada": 90, "gio":45} def inverter(d): d_new = dict() for k in d.keys(): val = d[k] d_new[val] = k return d_new print(inverter(d))
Example keys = ['red', 'green', 'blue'] values = ['# FF0000', '# 008000', '# 0000FF'] returns {'green': '# 008000', 'blue': '# 0000FF', 'red': '# FF0000'} def dictionary(keys, values): dic = dict() for x in range(len(keys)): dic[keys[x]] = values[x] return dic print(dictionary(["red", "green", "blue"],["#F0", "#08", "#00"]))
print(empty_dictionary([{},{},{}])) print(empty_dictionary([{1,2},{},{}]))
self._actual_floor = 0 def go_to_floor(self, f): if f > self._highest_floor or f<0: print ("Not allowed") elif f> self._actual_floor: print ("up" + str(f - self._actual_floor) + "floors") self._actual_floor = f elif f == self._actual_floor: print( "still") else: print( "down" + (self._actual_floor-f) + "floors") self._actual_floor = f mf = Elevator(6) print(mf.go_to_floor(3))
roman_value = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} for x in range(len(roman)): if roman[x] > roman[x-1]: integer_value += roman_value[roman[x]] - roman_value[roman[x-1]]* else: integer_value += roman_value[roman[x]] return integer_value print(roman_to_integer().converter('XIX'))
class TelephoneAccount: init(self, call_setup_fee, per_minute_fee): self.call_setup_fee = call_setup_fee self.per_minute_fee = per_minute_fee self.charge = 0 def add_call(self, duration): if duration == 0: pass else: self.charge += self.call_setup_fee + duration*self.per_minute_fee def get_bill(self): return self.charge RECURSION