Complete the following function such that it returns a dictionary which associates a number of each letter of the alphabet.
As an example, it associates
def get_alphabet_dictionary():
d = {'A':1,'B':2}
return dUsing the function written above complete the following function such that it receives a string as an argument and prints a numerical code obtained by replacing the letters of the string with their numerical value.
def get_code(s:str):
Using the function get_alphabeth_dictionary written above complete the following function such that
it receives a string as an argument and returns a list which contains the numerical code of each letter of the string passed.
As an example, if we pass "ABC" it must return [1,2,3]. Use list comprehension.
def get_code_list(s:str):
l = []
# populate the list
return l Complete the following function such that, given a dictionary similar to that of Exercise 1,
it returns a dictionary with the numerical values raised to the power of 2.
As an example, if the argument dictionary is d1 = {'A': 3,'B': 2} it must return d2 = {'A':9,'B':4}.
def get_squared_codes(d:dict):
"""
Given a dictionary which contains, for each key, a numerical value (similar to the one in exercise 1)
creates and returns a similar dictionary but such that the numerical value is squared.
:return: dict
"""
squared_dict = {l : d[l] ** 2 for l in d}
return squared_dictConsider a network consisting of
def generate_arcs(n_nodes:int):
'''
Generates and returns the list of arcs as tuples.
'''Consider a network consisting of
def generate_arcs(n_nodes:int):
'''
Generates and returns the list of arcs as tuples.
'''Complete the code below to write a class representing rectangles.
class Rectangle:
def __init__(self, length:float, height: float):
'''
Builds a rectangle given its length and height.
'''
def get_perimeter(self):
'''
:returns the perimeter of the rectangle
'''
def get_area(self):
'''
:returns the area of the rectangle
'''
def scale(self, scalar:float):
'''
Multiplies the dimensions of the rectangle by the scalar passed as an argument.
'''Complete the code below to write a class representing circles.
Pay particular attention at the constant
class Circle:
def __init__(self, radius:float):
'''
Builds a circle given its radius.
'''
def get_circumference(self):
'''
:returns the circumference of the circle
'''
def get_area(self):
'''
:returns the area of the circle
'''
def scale(self, scalar:float):
'''
Multiplies the radius by the scalar passed as an argument.
'''