Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write Python program that Reads in a series of positive integers, and Write out

ID: 3678263 • Letter: W

Question

Write Python program that Reads in a series of positive integers, and Write out the product of all the integers less than 25, and Write out the some of all the integers greater than or equal to 25. Use 0 as a sentinel value, which stops the input loop. To receive homework credit submit both the python source (*.py the file listing) and a screen shot of the running program. For each input number - If it is = 25 add it to the overall sum. Be sure to initialize product and sum to appropriate initial values.

Explanation / Answer

totalproduct = 0
totalSum = 0
num = 0
contuloop = 1;
count = 0
while(contuloop == 1):
   try:
       numstr = input("Enter positive integer")
       num = int(numstr)
       if(num == 0):
           contuloop == 0
           break
      
       if(num < 0):
           print("Enter a positive integer")
      
       if(num > 0):
           if(num >= 25):
               totalSum = totalSum + num
           else:
                if(count == 0):
                   totalproduct = num
                else:
                   totalproduct = totalproduct * num
           count = count+1
          
   except ValueError:
       print("Not an integer")

print("Total product:",totalproduct,"    Total sum:",totalSum)       

output

-------------------------------------------------------

totalproduct = 0
totalSum = 0
num = 0
contuloop = 1;
count = 0
while(contuloop == 1):
   try:
       numstr = input("Enter positive integer")
       num = int(numstr)
       if(num == 0):
           contuloop == 0
           break
      
       if(num < 0):
           print("Enter a positive integer")
      
       if(num > 0):
           if(num >= 25):
               totalSum = totalSum + num
           else:
                if(count == 0):
                   totalproduct = num
                else:
                   totalproduct = totalproduct * num
           count = count+1
          
   except ValueError:
       print("Not an integer")

print("Total product:",totalproduct,"    Total sum:",totalSum)       

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote