Question

Please solve it by Python 3 Write a program that asks the user for a positive...

Please solve it by Python 3

Write a program that asks the user for a positive integer limit and prints a table to visualize all factors of each integer ranging from 1 to limit. A factor i of a number n is an integer which divides n evenly (i.e. without remainder). For example, 4 and 5 are factors of 20, but 6 is not. Each row represents an integer between 1 and 20. The first row represents the number 1, the second row the number 2, and so forth. For a given position i (starting from 1) in a row n , '* ' indicates that i is a factor of n , and '- ' indicates that it is not.

The output of your program should look like this:

Maximum number to factorise: 20
* - - - - - - - - - - - - - - - - - - - 
* * - - - - - - - - - - - - - - - - - - 
* - * - - - - - - - - - - - - - - - - - 
* * - * - - - - - - - - - - - - - - - - 
* - - - * - - - - - - - - - - - - - - - 
* * * - - * - - - - - - - - - - - - - - 
* - - - - - * - - - - - - - - - - - - - 
* * - * - - - * - - - - - - - - - - - - 
* - * - - - - - * - - - - - - - - - - - 
* * - - * - - - - * - - - - - - - - - - 
* - - - - - - - - - * - - - - - - - - - 
* * * * - * - - - - - * - - - - - - - - 
* - - - - - - - - - - - * - - - - - - - 
* * - - - - * - - - - - - * - - - - - - 
* - * - * - - - - - - - - - * - - - - - 
* * - * - - - * - - - - - - - * - - - - 
* - - - - - - - - - - - - - - - * - - - 
* * * - - * - - * - - - - - - - - * - - 
* - - - - - - - - - - - - - - - - - * - 
* * - * * - - - - * - - - - - - - - - * 
?

Hint

Use the modulus operator (%) to test factors! Recall that m % n== 0 if and only if, n is a factor of m, e.g.:

print(20 % 5)
print(20 % 6)
print(20 % 7)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Explanation:

Here is the code which takes number n and then it uses the nested for loops to print the factors from 1 to n as * and non factors as -

feel free to comment if you need any help!

Code:

n = int(input("Maximum number to factorise: "))

for i in range(1, n+1):
  
for j in range(1, n+1):
if(i%j==0):
print('*', end='')
else:
print('-', end='')
  
print()


n = int(input(Maximum number to factorise: )) for i in range(1, n+1): for j in range(1, n+1): if(i%]==0): print(*, end=

Output:

Maximum number to factorise: 20 * - +-+-. **-*-. *---* *** *---- +*-*---* *-*----- **--*--- *- ****-*. **----* *-*-* **-*---

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!

PLEASE COMMENT IF YOU NEED ANY HELP!

Add a comment
Know the answer?
Add Answer to:
Please solve it by Python 3 Write a program that asks the user for a positive...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In HTML write a program that calculates and displays all factors of a number with a...

    In HTML write a program that calculates and displays all factors of a number with a function. A factor is any number that divides into a number evenly. For examples: Factors of 20 are 1,2,4,5,10,20 For the program: Prompt the user for a number or use an input Call a function to calculate all factors using loops and conditionals and modulus Display all factors to the page Bonus +5 If the factor is Even : Print it in Green If...

  • In Python, write a program that asks the user for a positive integer number. If the...

    In Python, write a program that asks the user for a positive integer number. If the user enters anything else, the program would ask the user to re-enter a number or enter -1 to quit. If it is a positive number, the program then prints out a multiplication table that goes up to that number. For example, if the user enters 10, the output would look something like this. https://www.vectorstock.com/royalty-free-vector/multiplication-table-on-white-background-vector-2721686

  • need this by tonight pls using python Write a program that asks the user to enter...

    need this by tonight pls using python Write a program that asks the user to enter a month (1 for January, 2 for February, and so on) and then prints the number of days in the month. For February, print “28 or 29 days”. Enter a month: 5 30 days Do not use a separate if/else branch for each month. Use Boolean operator

  • Python 3: Write a program in python that asks the user to enter a number that...

    Python 3: Write a program in python that asks the user to enter a number that contains 4 digits, i.e. in the range [1000-9999]. Your program MUST take it as a number integer. Print each digit on a separate line.

  • Write a python program that does the following. a. It asks the user to enter a...

    Write a python program that does the following. a. It asks the user to enter a 5-digit integer value, n. b. The program reads a value entered by the user. If the value is not in the right range, the program should terminate. c. The program calculates and stores the 5 individual digits of n. d. The program outputs a “bar code” made of 5 lines of stars that represent the digits of the number n. For example, the following...

  • using c++ 2. Write a program to read 3 integers a, b and c, your program...

    using c++ 2. Write a program to read 3 integers a, b and c, your program should print all factors of the integer c that exists between a and b. (a factor is an integer which evenly divides a number without leaving a remainder). Example: if a J 2, b 20 and c -30 then the factors of 30 between 2 and 20 are 2, 3, 5,6,10 and 15. CA. C Windows system32\cmd.exe an C: 2 20 30 Enter a,...

  • Write a program that asks the user to input a 4-digit integer and then prints the...

    Write a program that asks the user to input a 4-digit integer and then prints the integer in reverse. Your program needs to implement a function reverse that will take in as input the 4-digit number and print it out in reverse. Your code will consist of two files: main.s and reverse.s. Main.s will ask for the user input number and call the function reverse. For ARM/Data Structure needs to be able to run on Pi Reverse.s will take in...

  • Write a program that asks the user for a lower limit and an upper limit. The...

    Write a program that asks the user for a lower limit and an upper limit. The program finds all pairs of amicable numbers where the first number of the pair is between those limits. The second number of the pair may or may not be between the limits. To do this sensibly, write a function int sumDivisors( int num ); that returns the sum of all the proper divisors of num. The main program looks at each integer N between...

  • USING PYTHON 1. Write a small program that asks for an integer number from the user...

    USING PYTHON 1. Write a small program that asks for an integer number from the user and print all the prime numbers (2,3,5,7,etc) less than the input number. 2. How long it takes for your program to print the prime numbers less than 100. (Use magic functions)

  • using python Write a program that asks the user to enter a month (1 for January,...

    using python Write a program that asks the user to enter a month (1 for January, 2 for February, and so on) and then prints the number of days in the month. For February, print “28 or 29 days”. Enter a month: 5 30 days Do not use a separate if/else branch for each month. Use Boolean operators.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT