Advertisement
SimeonTs

SUPyF Lists - 05. Count of Odd Numbers in List

Jun 15th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.05 KB | None | 0 0
  1. """
  2. Lists
  3. Проверка: https://judge.softuni.bg/Contests/Practice/Index/924#4
  4.  
  5. 05. Count of Odd Numbers in List
  6.  
  7. Условие:
  8. Write a program to read a list of integers and find how many odd items it holds.
  9. Examples
  10. Input               Output
  11. 1 -2 3 4            2
  12. 3 9 -9 -6 1 -2      4
  13. 66 0 2 1            1
  14. Hints:
  15. -You can check if a number is odd if you divide them by 2 and check whether you get a remainder of 1.
  16. -Odd numbers, which are negative, have a remainder of -1.
  17. """
  18.  
  19. """
  20. How I solved it:
  21.  
  22. First we will take all the added integers on one line divided by space and it will add them in a new list one by one:
  23. Then, we need to create a count_of_odd_numbers variable so we can store the count there.
  24. Next, we will create a For Loop to check for each number in the list, if its Odd. And if its odd we will add 1 to the
  25. odd_nums counter
  26. And finally to print the output:
  27. """
  28.  
  29. nums = [int(item) for item in input().split(" ")]
  30.  
  31. odd_nums_count = 0
  32.  
  33. for item in nums:
  34.     if item % 2 != 0:
  35.         odd_nums_count += 1
  36.  
  37. print(odd_nums_count)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement