question archive Find the terms of any linear sequence given by the rule Un = an + b, where a and b are integers specified by the user and n is a positive integer, and print them in increasing order (for example if the user inputs a=3, b=?4, the first few terms that should be printed are ?1, 2, 5, 8, 11
Subject:Computer SciencePrice:4.86 Bought12
Find the terms of any linear sequence given by the rule Un = an + b, where a and b are integers specified by the user and n is a positive integer, and print them in increasing order (for example if the user inputs a=3, b=?4, the first few terms that should be printed are ?1, 2, 5, 8, 11...). The user also will specify how many terms the program should print. The user should be allowed to choose another sequence and for the number of terms chosen the program should calculate and print their sum. Using pseudocode or flowchart or both.
def sequence(a,b,n): sum=0 for i in range(n): sum += a*(i+1) + b print(sum) return sum while True: q = input('Do you want to print a sequence? (yes/no): ') if q == 'yes': a = int(input('Enter the value of a: ')) b = int(input('Enter the value of b: ')) n = int(input('Enter the number of sequence to generate: ')) s = sequence(a,b,n) print('Sum =',s) else: break;
Please see the attached file for the complete solution