Lite fiks i oppgave 3
This commit is contained in:
		
							parent
							
								
									96afa6a682
								
							
						
					
					
						commit
						7a3eae94b9
					
				
							
								
								
									
										13
									
								
								stat_kalk.py
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								stat_kalk.py
									
									
									
									
									
								
							| @ -10,8 +10,11 @@ ESP meny: | ||||
|     4. List ut verdiene | ||||
|     5. Avslutt | ||||
| Ditt valg:""") | ||||
|     i = int(input()) | ||||
|     if i not in range(1,6): raise ValueError() | ||||
|     try: | ||||
|         i = int(input()) | ||||
|     except ValueError: | ||||
|         return 0 | ||||
|     if i not in range(1,6): return 0 | ||||
|     return i | ||||
| 
 | ||||
| def read_values(values): | ||||
| @ -23,7 +26,7 @@ def read_values(values): | ||||
|             break | ||||
|     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}') | ||||
| 
 | ||||
| def main(): | ||||
| @ -31,6 +34,8 @@ def main(): | ||||
|     values = [] | ||||
|     while True: | ||||
|         match choose_action(): | ||||
|             case 0: | ||||
|                 print('Ikke et gyldig valg!') | ||||
|             case 1: | ||||
|                 # Write numbers | ||||
|                 read_values(values) | ||||
| @ -39,7 +44,7 @@ def main(): | ||||
|             case 3: | ||||
|                 #mean, std | ||||
|                 try: | ||||
|                     print(print_statistics(values)) | ||||
|                     print(get_statistics(values)) | ||||
|                 except ZeroDivisionError: | ||||
|                     print('Tom liste!') | ||||
|             case 4: | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user