- 8 heures
- Facile
Ce cours est visible gratuitement en ligne.
course.header.alt.is_video
course.header.alt.is_certifying
J'ai tout compris !Mis à jour le 28/03/2024
Solve Common Programming Problems With Design Patterns in Python
Compétences évaluées
- Solve common programming problems with design patterns in Python
Question 1
What is a design pattern?
A recurring method for finishing code before deadline.
A base class used for modification.
A reusable solution to a recurring problem.
A sequence of steps that ensure that code conforms to PEP 8.
Question 2
Which of these is NOT a good reason for using the constant design for the golden ratio, 1.618…?
A consistent level of accuracy will be used for this value throughout the code.
If the value is replaced by another, it is easy to find all places where it is used in the code.
Developers reading the code will easily understand what the 1.618… represents because it has a name in the code such as
VALUE_GOLDEN_RATIO
If the value gets used many times, the code will run significantly faster when using the constant design pattern.
Question 3
The list of colors in the following code may be expanded or modified in the future. Which of the following is a suitable way to implement the constant design pattern to make future updates straightforward and resistant to bugs?
print("Choose a color:") for color in ["red", "green", "yellow"]: print(color) for ii in range(0, 3): input_color = input() if input_color not in ["red", "green", "yellow"]: print("oops") exit()
NUMBER_OF_COLORS = 3 print("Choose a color:") for color in ["red", "green", "yellow"]: print(color) for ii in range(0, NUMBER_OF_COLORS): input_color = input() if input_color not in ["red", "green", "yellow"]: print("oops") exit()
COLORS_FOR_MODULE = ["red", "green", "yellow"] print("Choose a color:") for color in COLORS_FOR_MODULE: print(color) for ii in range(0, len(COLORS_FOR_MODULE)): input_color = input() if input_color not in COLORS_FOR_MODULE: print("oops") exit()
COLOR_1 = "red" COLOR_2 = "green" COLOR_3 = "yellow" print("Choose a color:") for color in [COLOR_1, COLOR_2, COLOR_3]: print(color) for ii in range(0, 3): input_color = input() if input_color not in [COLOR_1, COLOR_2, COLOR_3]: print("oops") exit()
- Formations jusqu’à 100 % financées
- Date de début flexible
- Projets professionnalisants
- Mentorat individuel