PYTHON   60
pares impares if else py
Guest on 13th August 2022 08:02:27 AM


  1. # -*- coding: utf-8 -*-
  2. """
  3. Spyder Editor
  4.  
  5. @author: fradim
  6. """
  7. '''
  8. Given an integer n, n>0, and a sequence with n
  9. whole numbers, determine how many numbers in the
  10. sequence are even and how many are odd.  
  11. For example, for the sequence
  12.  
  13.     6 -2 7 0 -5 8 4
  14.    
  15. your program should write the number 4 to the
  16. number of evens and 2 for the number of odds.
  17. '''
  18. #1 read the string size
  19. n = int(input("Enter n: "))
  20.  
  21. #2 initialize counters
  22. count_pair = 0
  23. odd_count = 0
  24.  
  25. # 3 read sequence and determine on evens and odds
  26. i = 0
  27. while i < n:
  28.    num = int(input("Enter a number: "))
  29.    remainder = num %2
  30.    if remainder == 0:
  31.        count_par = count_par + 1
  32.    else: # else
  33.        odd_count = odd_count + 1
  34.    i = i + 1
  35.  
  36. #4 write the answer
  37. print(f"{count_pair} pairs")
  38. print(f"{odd_count} odd")

Raw Paste

Login or Register to edit or fork this paste. It's free.