r/pythonhelp • • Feb 27 '21

Help I am stuck on the second half of figuring out this python code.

Post image
0 Upvotes

7 comments sorted by

1

u/scoopulanang Feb 28 '21

Well, just ask the user for both of the numbers. Use the input function and don't forget to cast your input to integers.

Create a while loop to run while your first number is greater than 0. print out the larger number minus the smaller number and then subtract your smaller number from the larger one and store the new value in the pre-existing variable that you created to hold you larger number. Then subtract 1 from your smaller number and store that new value in the pre-existing variable for the smaller number.

You might have to modify the condition to run your while loop. I can't really tell if you want to keep subtracting into the negatives or stop when your larger number is a single digit.

1

u/bouiiiii018 Feb 28 '21

I would like to stop subtracting into the negatives, how can I do that?

1

u/scoopulanang Feb 28 '21
while larger_number - smaller_number > 0:
    #do something

It's as simple as that

1

u/bouiiiii018 Feb 28 '21

how do I incorporate that in my code?

print("Starting the countdown from", part2)

for i in reversed(range(9, part1 + 1)):

result = part2 - i

print(part2, "-", i, "gives us", result)

part2 = result

1

u/scoopulanang Feb 28 '21

So, if you want to use a for loop. You can do this:

part1 = int(input())
part2 = int(input())

for i in range(part1, 0, -1):
    if part2 - i < 0:
        break
    print(part2,"-",i,"gives us",part2-i)
    part2 -= i

1

u/bouiiiii018 Feb 28 '21

Thank you so much!!