Nizza
This commit is contained in:
		
							
								
								
									
										23
									
								
								3. Übungen/28.04.2022/selectionsort.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								3. Übungen/28.04.2022/selectionsort.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,23 @@ | ||||
| # Make a programm which asks the user for an input and then sorts the input of the user | ||||
|  | ||||
| # First ask the user how long he want the Array to be | ||||
| array_length=int(input("Wie viele Zahlen sollen sortiert werden")) | ||||
| # Second make an array | ||||
| array=[] | ||||
| # Third ask the user for number input | ||||
| for i in range(array_length): | ||||
|     number=float(input("Bitte mir einfach eine Zahl geben")) | ||||
|     # Now append that number to the array | ||||
|     array.append(number) | ||||
|  | ||||
| # Now sort them with the Help of the selection sort algorithm | ||||
| for i in range(len(array)): | ||||
|    min_= i | ||||
|    for j in range(i+1, len(array)): | ||||
|       if array[min_] > array[j]: | ||||
|          min_ = j | ||||
|    #swap | ||||
| array[i], array[min_] = array[min_], array[i] | ||||
| # main | ||||
| for i in range(len(array)): | ||||
|    print(array[i]) | ||||
		Reference in New Issue
	
	Block a user