Lite fiks i oppgave 3
This commit is contained in:
parent
96afa6a682
commit
7a3eae94b9
11
stat_kalk.py
11
stat_kalk.py
@ -10,8 +10,11 @@ ESP meny:
|
|||||||
4. List ut verdiene
|
4. List ut verdiene
|
||||||
5. Avslutt
|
5. Avslutt
|
||||||
Ditt valg:""")
|
Ditt valg:""")
|
||||||
|
try:
|
||||||
i = int(input())
|
i = int(input())
|
||||||
if i not in range(1,6): raise ValueError()
|
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:
|
||||||
|
Loading…
Reference in New Issue
Block a user