8.9 LAB: Number pattern
Write a recursive function called print_num_pattern() to outputthe following number pattern.
Given a positive integer as input (Ex: 12), subtract anotherpositive integer (Ex: 3) continually until a negative value isreached, and then continually add the second integer until thefirst integer is again reached. For this lab, do not end outputwith a newline.
Do not modify the given main program.
Input 17 5
Your output 17 12 7 2 -3 -8 -13 -18 -23 -28 -33 -38 -43-48 -53 -58
Expected output 17 12 7 2 -3 2 7 12 17
I NEED HELP IN THE LAST ONE BECAUSE IF I TYPE IN ANINPUT 17&5 I GET THE WRONG OUTPUTS.
THIS IS MY CODE SO FAR.
def print_num_pattern(num1,num2): if (num1 == -(num2)): print(num1, end = ' ') return
print(num1, end = ' ') print_num_pattern(num1 - num2, num2)
print(num1, end = ' ')if __name__ == "__main__": num1 = int(input()) num2 = int(input()) print_num_pattern(num1, num2)
8.9 LAB: Number pattern Write a recursive function called print_num_pattern() to output the following number pattern. Gi
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am