INF120/stat_kalk.py
2023-11-01 17:30:59 +01:00

56 lines
1.4 KiB
Python

import inf120stat as stat
def choose_action():
#returns number from 1 to 5
print("""
ESP meny:
1. Les inn verdier
2. Tøm verdi listen
3. Vis gjennomsnitt og standardavvik
4. List ut verdiene
5. Avslutt
Ditt valg:""")
try:
i = int(input())
except ValueError:
return 0
if i not in range(1,6): return 0
return i
def read_values(values):
while True:
try:
values.append(float(input('Ny verdi (Enter = slutt):')))
except ValueError:
print('Verdier kan kunn være gyldige flyttall!')
break
return values
def get_statistics(values):
return(f'Antall verdier: {len(values)}, gjennomsnitt: {stat.mean(values):.2f}, standardavvik: {stat.std(values):.2f}')
def main():
print('Starter Enkelt statistikk program (ESP)')
values = []
while True:
match choose_action():
case 0:
print('Ikke et gyldig valg!')
case 1:
# Write numbers
read_values(values)
case 2:
values = []
case 3:
#mean, std
try:
print(get_statistics(values))
except ZeroDivisionError:
print('Tom liste!')
case 4:
print(values)
case 5:
exit('Hadebra :)')
if __name__ == '__main__':
main()