Advertisement
biswasrohit20

q2

Mar 12th, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. # Q2
  2.  
  3. start = int(input("input the initial value: "))
  4. end = int(input("input the limit value: "))
  5. all_num = []
  6. num = start
  7. while num < end:
  8. all_num.append(num)
  9. if num % 2 == 0 and num % 3 == 0:
  10. num = num + 3
  11. elif num % 2 == 0 and num % 3 != 0:
  12. num = num + (num % 3)
  13. elif num % 3 == 0 and num % 2 != 0:
  14. num = num + (num % 2)
  15. elif num % 3 != 0 and num % 2 != 0:
  16. num = (2 * num) + 1
  17. all_num.append(num)
  18. numberOfTerms = len(all_num)
  19. maxTerm = all_num[-1]
  20. print(f'{str(numberOfTerms)} terms are required to reach or pass {str(end)}')
  21. print(f'The last term is {str(maxTerm)}')
  22. print(f'The average of all term is {str(sum(all_num)/numberOfTerms)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement