Question

Write a program that takes in an integer in the range 20-98 as input. The output...

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

Homework Answers

Answer #1

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.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
/* This program should check if the given integer number is prime. Reminder, an integer number...
/* This program should check if the given integer number is prime. Reminder, an integer number greater than 1 is prime if it divisible only by itself and by 1. In other words a prime number divided by any other natural number (besides 1 and itself) will have a non-zero remainder. Your task: Write a method called checkPrime(n) that will take an integer greater than 1 as an input, and return true if that integer is prime; otherwise, it should...
4) Write a Java program using Conditions: Write a program where it will ask user to...
4) Write a Java program using Conditions: Write a program where it will ask user to enter a number and after that it will give you answer how many digits that number has. Steps: 1) Create Scanner object and prompt user to enter the number and declare variable integer for input 2) Use if else condition with && condition where you will specify the digits of numbers by writing yourself the digit number that should display: Example(num<100 && num>=1), and...
(8 marks) Write a program to ask user to input an integer and display the special...
Write a program to ask user to input an integer and display the special pattern accordingly. REQUIREMENTS The user input is always correct (input verification is not required). Your code must use loop statements (for, while or do-while). Your program should use only the following 3 output statements, one of EACH of the followings: System.out.print("-"); // print # System.out.print("+"); // print + System.out.println(); // print a newline Your code must work exactly like the following example (the text in bold...
Complete in python3 , I know how to start a countdown but im having trouble displaying...
Complete in python3 , I know how to start a countdown but im having trouble displaying the word instead of zero Countdown Write a function as follows. * function name: countdown * parameters: start (int) whoopee_word (string) * returns: N/A * operation: Count down from start to 1. Instead of 0, print the whoopee_word. BUT: - If start is less than 1 or greater than 20, print "start is out of range" and exit the function - If start is...
Now we want to display which error was thrown in our voting program. ( BOTH QUESTIONS...
Now we want to display which error was thrown in our voting program. ( BOTH QUESTIONS ARE PYTHONS PROGRAMS) Add the appropriate code to the try/except statement so the exception is displayed. Run the program and, when prompted, enter the word 'old' so your output matches the output under Desired Output. # Set the variable age = input("What is your age?") # Insert a try/except statement # here when you convert the input # to a number using int() try:...
This program will output a right triangle based on user specified height triangle_height and symbol triangle_char....
This program will output a right triangle based on user specified height triangle_height and symbol triangle_char. (1) The given program outputs a fixed-height triangle using a * character. Modify the given program to output a right triangle that instead uses the user-specified triangle_char character. (1 pt) (2) Modify the program to use a loop to output a right triangle of height triangle_height. The first line will have one user-specified character, such as % or *. Each subsequent line will have...
C++ programming Write a program that reads a comma-separated file (CSV) with integer values and prints...
C++ programming Write a program that reads a comma-separated file (CSV) with integer values and prints the number of integer values in the file. Your program's input will be a string with the name of the file. If the file does not exist, then the program must print: Error opening the file For example, given the following CSV file input1.csv: 1,10,20,30,40 The output of your program must be: 5 You can safely assume that the input file will be a...
Write a C program that runs on ocelot for a mini calculator using only the command...
Write a C program that runs on ocelot for a mini calculator using only the command line options. You must use getopt to parse the command line. The calculator will only do addition, subtraction, multiplication, division, and a power of 2. Usage: minicalc [-a num] [-d num] [-m num] [-s num] [-x] value • The variable value is the starting value. • Value should be validated to be an integer between 1 and 50 inclusive. Error message and usage shown...
Program P1 1) integer A, B; 2) input (A); 3) while (A > 0) 4) {...
Program P1 1) integer A, B; 2) input (A); 3) while (A > 0) 4) { 5) B = 1; 6) if (A < 10) 7) B = 0; 8) if (A < 20 or A > 25) 9) B = A * B; 10) else 11) B = A + B; 12) output (A, B); 13) input (A); 14) } 15) output (“Program ends.”); 16) end; T = {t1=<1>, t2=<33>, t3=<‐1>} or T = {t1=, t2=, t3=} 6. If...
The function named myRandomNum that returns a random integer in the range [1, 100] is defined...
The function named myRandomNum that returns a random integer in the range [1, 100] is defined as follows: int myRandomNum () { return rand()%100 + 1; } Now, write a program (code fragment) that repeatedly generates and prints random integers in the range [1, 100]. The program must stop when the absolute value of the difference between successive printed values is less than 5. Two sample output is given to help you understand the problem: 1. The program can possibly...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT