2023-10-23 19:45:15 +00:00
|
|
|
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:""")
|
2023-11-01 16:30:59 +00:00
|
|
|
try:
|
|
|
|
i = int(input())
|
|
|
|
except ValueError:
|
|
|
|
return 0
|
|
|
|
if i not in range(1,6): return 0
|
2023-10-23 19:45:15 +00:00
|
|
|
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
|
|
|
|
|
2023-11-01 16:30:59 +00:00
|
|
|
def get_statistics(values):
|
2023-10-23 19:45:15 +00:00
|
|
|
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():
|
2023-11-01 16:30:59 +00:00
|
|
|
case 0:
|
|
|
|
print('Ikke et gyldig valg!')
|
2023-10-23 19:45:15 +00:00
|
|
|
case 1:
|
|
|
|
# Write numbers
|
|
|
|
read_values(values)
|
|
|
|
case 2:
|
|
|
|
values = []
|
|
|
|
case 3:
|
|
|
|
#mean, std
|
|
|
|
try:
|
2023-11-01 16:30:59 +00:00
|
|
|
print(get_statistics(values))
|
2023-10-23 19:45:15 +00:00
|
|
|
except ZeroDivisionError:
|
|
|
|
print('Tom liste!')
|
|
|
|
case 4:
|
|
|
|
print(values)
|
|
|
|
case 5:
|
|
|
|
exit('Hadebra :)')
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|