Advertisement
Guest User

Even/Odd Code 3

a guest
Jun 15th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | Help | 0 0
  1. userFile = input('File: ')
  2. positiveSum = 0
  3. negativeCount = 0
  4.  
  5.  
  6. openedUserFile = open(userFile, "r")
  7. openedEvenFile = open("even.txt", "w")
  8. openedOddFile = open("odd.txt", "w")
  9.  
  10.  
  11. for line in openedUserFile:
  12. line = int(line)
  13. if line % 2 == 0 or line == 0:
  14. positiveSum += line
  15. evenLine = line
  16. evenLine = str(line)
  17. openedEvenFile.write(evenLine + " ")
  18.  
  19.  
  20. else:
  21. oddLine = line
  22. oddLine = str(line)
  23. openedOddFile.write(oddLine + " ")
  24. for line in openedUserFile:
  25. line = int(line)
  26. if line > 0:
  27. negativeCount += line
  28.  
  29.  
  30. print('\nThe sum of the positive numbers:', positiveSum)
  31. print('The count of the negative numbers:', negativeCount)
  32.  
  33.  
  34. #openedUserFile.close()
  35. openedEvenFile.close()
  36. openedOddFile.close()
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement