Advertisement
Guest User

Even/Odd Code 2

a guest
Jun 15th, 2024
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 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.  
  25.  
  26. for line in openedUserFile:
  27. line = lint.split
  28. line = int(line)
  29. if line > 0:
  30. negativeCount += line
  31.  
  32.  
  33. print('\nThe sum of the positive numbers:', positiveSum)
  34. print('The count of the negative numbers:', negativeCount)
  35.  
  36.  
  37. #openedUserFile.close()
  38. openedEvenFile.close()
  39. openedOddFile.close()
  40.  
  41.  
  42.  
  43.  
  44.  
  45. ## RESULTS
  46. ## userfile/samplefile.txt:
  47. ## 2
  48. ## -1
  49. ## 0
  50. ## 6
  51. ## -23
  52. ## 1
  53. ## 62
  54.  
  55. ## even.txt result: 20662
  56. ## odd.txt result: -1-231
  57.  
  58. ## positiveSum result: 70
  59. ## negativeCount result: 0
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement