Python voor gevorderde ontwikkelaars
Jasmin Ludolf
Senior Data Science Content Developer
# Printen
print("Password is accepted!")
Password is accepted!
# Datatypes controleren
type(print)
builtin_function_or_method
# Wachtwoordpogingen
for attempt in range(1, 4):
print("Attempt", attempt)
Attempt 1
Attempt 2
Attempt 3
$$
$$
$$

# Lijst met bereidingstijden (minuten) preparation_times = [19.23, 15.67, 48.57, 23.45, 12.06, 34.56, 45.67]# Langste bereidingstijd print(max(preparation_times))
48.57
# Kortste bereidingstijd
print(min(preparation_times))
12.06
# Totale bereidingstijd
print(sum(preparation_times))
199.21
# Totaal opslaan total_time = sum(preparation_times)# Afronden op één decimaal print(round(total_time, 1))
199.2
# Aantal bestellingen
print(len(preparation_times))
7
# Gemiddelde bereidingstijd
print(sum(preparation_times) / len(preparation_times))
28.4585714
# Lengte van een string
print(len("Burger Hub"))
10
# Sorteer een lijst oplopend
print(sorted(preparation_times))
[12.06, 15.67, 19.23, 23.45, 34.56,
45.67, 48.57]
# Sorteer een string alfabetisch
print(sorted("George"))
['G', 'e', 'e', 'g', 'o', 'r']
# Totale bereidingstijd
print(sum(preparation_times))
199.21
# Totale bereidingstijd berekenen # Variabele om op te hogen time_count = 0# Loop door de tijden for time in preparation_times:# Tel elke tijd op bij time_count time_count += timeprint(time_count)
sum() is herbruikbaar, korter, schoner
en minder foutgevoelig!19.23
34.9
83.47
106.92
118.98
153.54
199.21
Python voor gevorderde ontwikkelaars