Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Q2
- start = int(input("input the initial value: "))
- end = int(input("input the limit value: "))
- all_num = []
- num = start
- while num < end:
- all_num.append(num)
- if num % 2 == 0 and num % 3 == 0:
- num = num + 3
- elif num % 2 == 0 and num % 3 != 0:
- num = num + (num % 3)
- elif num % 3 == 0 and num % 2 != 0:
- num = num + (num % 2)
- elif num % 3 != 0 and num % 2 != 0:
- num = (2 * num) + 1
- all_num.append(num)
- numberOfTerms = len(all_num)
- maxTerm = all_num[-1]
- print(f'{str(numberOfTerms)} terms are required to reach or pass {str(end)}')
- print(f'The last term is {str(maxTerm)}')
- print(f'The average of all term is {str(sum(all_num)/numberOfTerms)}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement