Lite fiks i oppgave 3

This commit is contained in:
Trygve 2023-11-01 17:30:59 +01:00
parent 96afa6a682
commit 7a3eae94b9

View File

@ -10,8 +10,11 @@ ESP meny:
4. List ut verdiene 4. List ut verdiene
5. Avslutt 5. Avslutt
Ditt valg:""") Ditt valg:""")
i = int(input()) try:
if i not in range(1,6): raise ValueError() i = int(input())
except ValueError:
return 0
if i not in range(1,6): return 0
return i return i
def read_values(values): def read_values(values):
@ -23,7 +26,7 @@ def read_values(values):
break break
return values return values
def print_statistics(values): def get_statistics(values):
return(f'Antall verdier: {len(values)}, gjennomsnitt: {stat.mean(values):.2f}, standardavvik: {stat.std(values):.2f}') return(f'Antall verdier: {len(values)}, gjennomsnitt: {stat.mean(values):.2f}, standardavvik: {stat.std(values):.2f}')
def main(): def main():
@ -31,6 +34,8 @@ def main():
values = [] values = []
while True: while True:
match choose_action(): match choose_action():
case 0:
print('Ikke et gyldig valg!')
case 1: case 1:
# Write numbers # Write numbers
read_values(values) read_values(values)
@ -39,7 +44,7 @@ def main():
case 3: case 3:
#mean, std #mean, std
try: try:
print(print_statistics(values)) print(get_statistics(values))
except ZeroDivisionError: except ZeroDivisionError:
print('Tom liste!') print('Tom liste!')
case 4: case 4: