blooming8

vettore pari più max .py

Jun 10th, 2020
1,239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. ## Caricato un vettore di numeri pari ricercarne il valore massimo ##
  2.  
  3. ' ricerca del massimo '
  4.  
  5. def cerca_max(vett, dim):
  6.    
  7.     for i in range(dim):
  8.         if i == 0:
  9.             max = vett[i]
  10.         else:
  11.             if max < vett[i]:
  12.                 max = vett[i]
  13.                
  14.     return max
  15.    
  16. def main():
  17.    
  18.     vett, dim = [], 4
  19.      
  20.     ' caricamento del vettore '
  21.      
  22.     for i in range(dim):
  23.         num = int(input("Numero pari: "))
  24.      
  25.         while num % 2 != 0:
  26.             num = int(input("Devi inserire un numero pari! "))
  27.            
  28.         vett.append(num)
  29.                
  30.     ' stampa dei risultati '
  31.      
  32.     print("Numeri pari: ", vett)
  33.      
  34.     print("\nValore massimo: ", cerca_max(vett, dim))
  35.    
  36.    
  37. if __name__ == '__main__':
  38.     main()
Advertisement
Add Comment
Please, Sign In to add comment