Question
In python can anyone help me to implement function using rang-based-for-loops def revrange(a,b): Returns the tuple (b-1, b-2, ..., a) Note that this tuple
In python can anyone help me to implement function using rang-based-for-loops def revrange(a,b): """ Returns the tuple (b-1, b-2, ..., a) Note that this tuple is the reverse of tuple(range(a,b)) Parameter a: the "start" of the range Precondition: a is an int <= b Parameter b: the "end" of the range Precondition: b is an int >= a """
#I have this rn
reverse = 0
for x in range(a,b):
if a <= b and b >= a:
reverse = range(a,b)
tups = tuple(reverse)
print(tups)
tups1 = list(tups)
tups3 = sorted(tups1, reverse = True)
print(tups3) tups = tuple(tups3)
return tups
#but getting this error
The call revrange(3) crashed. Traceback (most recent call last): UnboundLocalError: local variable 'tups' referenced before assignment
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started