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

You must submit shots of the Python screens showing your code and your output fo

ID: 3715452 • Letter: Y

Question

You must submit shots of the Python screens showing your code and your output for any response that includes Python. 1. Given the arithmetic sequence: 3, 5,7, 9, a. Write a python recursive function that will return the nth term in the sequence. Write code that includes a for loop which will invoke the function and then print the first 6 terms (e.g., for each term "Term #1-5" ) and the sum of those six terms b. Construct the trace of the function showing memory and output, including return values produced at each step of the function. Use the trace models in your textbook and practice problems to guide you. c. Modify your function so that it becomes a function that will run an infinite number of times. Submit screen shots of the modified function and the first page of output

Explanation / Answer

1)

#a
#function that returns that nth term in the sequence...3,5,7,9
def nth_term1(x,n):
if(n==1):#base case
return x
return nth_term1(x+2,n-1)#recursive call
#b
#now trace function for the above function
#in every call printing x,n values..
def nth_term2(x,n):
print("x :",x,"n:",n)
if(n==1):#n==1, means x became the nth term
return x
return nth_term2(x+2,n-1)#recursive call
#c modifying function so that it become...infinit
#by removing base case
def nth_term3(x,n):
print("x :",x,"n:",n)
#base case removed so it will never break//
return nth_term3(x+2,n-1)#recursive call

print(nth_term1(3,5))
print(nth_term2(3,5))
nth_term3(3,5);

output

:>> ================================ RESTART ================================
>>>
11
x : 3 n: 5
x : 5 n: 4
x : 7 n: 3
x : 9 n: 2
x : 11 n: 1
11
x : 3 n: 5
x : 5 n: 4
x : 7 n: 3
x : 9 n: 2
x : 11 n: 1
x : 13 n: 0
x : 15 n: -1
x : 17 n: -2
x : 19 n: -3
x : 21 n: -4
x : 23 n: -5
x : 25 n: -6
x : 27 n: -7
x : 29 n: -8
x : 31 n: -9
x : 33 n: -10
x : 35 n: -11
x : 37 n: -12
x : 39 n: -13
x : 41 n: -14
x : 43 n: -15
x : 45 n: -16
x : 47 n: -17
x : 49 n: -18
x : 51 n: -19
x : 53 n: -20
x : 55 n: -21
x : 57 n: -22
x : 59 n: -23
x : 61 n: -24
x : 63 n: -25
x : 65 n: -26
x : 67 n: -27
x : 69 n: -28
x : 71 n: -29
x : 73 n: -30
x : 75 n: -31
x : 77 n: -32
x : 79 n: -33
x : 81 n: -34
x : 83 n: -35
x : 85 n: -36
x : 87 n: -37
x : 89 n: -38
x : 91 n: -39
x : 93 n: -40
x : 95 n: -41
x : 97 n: -42
x : 99 n: -43
x : 101 n: -44
x : 103 n: -45
x : 105 n: -46
x : 107 n: -47
x : 109 n: -48
x : 111 n: -49
x : 113 n: -50
x : 115 n: -51
x : 117 n: -52
x : 119 n: -53
x : 121 n: -54
x : 123 n: -55
x : 125 n: -56
x : 127 n: -57
x : 129 n: -58
x : 131 n: -59
x : 133 n: -60
x : 135 n: -61
x : 137 n: -62
x : 139 n: -63
x : 141 n: -64
x : 143 n: -65
x : 145 n: -66
x : 147 n: -67
x : 149 n: -68
x : 151 n: -69
x : 153 n: -70
x : 155 n: -71
x : 157 n: -72
x : 159 n: -73
x : 161 n: -74
x : 163 n: -75
x : 165 n: -76
x : 167 n: -77
x : 169 n: -78
x : 171 n: -79
x : 173 n: -80
x : 175 n: -81
x : 177 n: -82
x : 179 n: -83
x : 181 n: -84
x : 183 n: -85
x : 185 n: -86
x : 187 n: -87
x : 189 n: -88
x : 191 n: -89
x : 193 n: -90
x : 195 n: -91
x : 197 n: -92
x : 199 n: -93
x : 201 n: -94
x : 203 n: -95
x : 205 n: -96
x : 207 n: -97
x : 209 n: -98
x : 211 n: -99
x : 213 n: -100
x : 215 n: -101
x : 217 n: -102
x : 219 n: -103
x : 221 n: -104
x : 223 n: -105
x : 225 n: -106
x : 227 n: -107
x : 229 n: -108
x : 231 n: -109
x : 233 n: -110
x : 235 n: -111
x : 237 n: -112
x : 239 n: -113
x : 241 n: -114
x : 243 n: -115
x : 245 n: -116
x : 247 n: -117
x : 249 n: -118
x : 251 n: -119

.........

it continues....upto...heap is full

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