Write a program that takes in an integer in the range 20-98 as input. The output is a countdown starting from the integer, and stopping when both output digits are identical. I already did the coding part:num = int(input()) if 20 <= num <= 98: while num % 11!=0: print(num) num -= 1 print(num) else: print('Input must be 20-98')
Question: How do you know when to use %? Why is it %11 and why not %12 or %15? How do you know when you have to use %? Thank you
How do you know when to use %? How do you know when you have to use %?
When we want to find the remainder , we have to use %. Here we want to find the remainder of num%11. and check if it is zero or not.If it is zero then num is exactly divisible by 11 otherwise num is not exactly divisible by 11. So we used % operator.
Why is it %11 and why not %12 or %15?
Numbers in the range of 20-98 that have both digits equal are 22,33,44,55,66,77,88. All these are multiples of 11. So if a number in the range of 20-98 is exactly divisible by 11. Then it has both digits equal. So we we have chose %11 instead of %12 or %15.
Get Answers For Free
Most questions answered within 1 hours.