+ 1

Can someone help me pls

I need to turn this function into a recursive function but i keep getting an error def traffic_sign(n): while n>0: print('No Parking') n = n > 1 Any help is greatly appreciated.

29th Apr 2017, 1:28 AM
Tamara
2 Antworten
+ 6
You need at least to correctly indent your code ^^ def traffic_sign(n): while n>0: print('No Parking') n = n > 1 Actually the last line assign the result of test ( n > 1 ) to the 'n' variable, wich is probably not what you are expected :P ( and I don't know what you want to do, so I don't know if I correctly indent it -- should be the last assignment inside the 'while' loop or not? -- however, you should have a base case to your loop, so you need to have a case where 'n' comes to be zero or negative to avoid infinite loop :P ) Anyway, you have to call your function inside itself to make it a 'recursive' one ;)
29th Apr 2017, 1:58 AM
visph
visph - avatar
+ 1
def traffic_sign(n): if n == 0: return n else: print('No Parking') return traffic_sign(n-1) traffic_sign(10)
29th Apr 2017, 5:35 AM
richard