enter image description hereFind and print the range value of three remainder values from part 1 as range(start:B, stop: A, Step: C)
From the range value given from the previous step, do a new range for the new value and print it.
(HELP) I don't really know how to do this
def my_homework():
x = 500
y = 400
z = 300
a = x % 90
b = y % 90
c = z % 90
print(a)
print(b)
print(c)
for t in range(a,b,c):
print(t)
my_homework()
CodePudding user response:
There are a lot of issues in the program so I'll just tell you one by one
1 - range(start: B, stop: A, Step: C) question says this. and you are doing trying to run the below code.
for t in range(a,b,c):
ok just changed the position but why it's not working, you need to understand the range a little bit, range() function have three parameters [starting point , stop point , step]
The first two are self-defining so I'm leaving those the third one is the value that will be incremented at every iteration e.g :
first = 0 ; second = 9 ; third = 2
the loop will start from first, will trying to go till second(stop) and at each step, a third will be added to the first(start value)
for a brief explanation see the below link :
for t in range(a,b,c): => This thing will not work because if you check the value of a (start point) it is greater than b (endpoint) so the loop will have 0 iterations.
2 - The for loop needs to be in the function and not outside because the variables
a = x % 90
b = y % 90
c = z % 90
they are declared inside the function and must be used somewhere inside the function.
3 - range() functions actually returns a list of numbers and to find the value you just need to find its length so, once you have done the above steps just write this code.
print(len(range(b , a, c)))
4 - Last thing this will work but to understand it better you might want to change the value of z to something lower e.g
z = 1
so you will get 1 as a remainder in c that means the greater value of range() by having 1 increment instead of 30.