1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
NNADVOKAT [17]
4 years ago
12

Python Write a program that asks the user for an integer and then prints out all its factors.

Computers and Technology
1 answer:
scoray [572]4 years ago
7 0

Answer:

def display_factors(num):

   for counter in range(1, num+1):

       if num % counter == 0:

           print(counter)

int_num= int(input("Enter a number : "))

print("The factors for {} are : ".format(int_num))

display_factors(int_num)

Explanation:

The function display_factors is used to display all factors of a number entered by a user.

  • In this  for counter in range(1, num+1) the for loop is iterated until counter is greater  to num is false.   Counter variable starts from 1 and ends when it gets greater than the input number.
  • if num % counter == 0: In this statement, each loop  iteration, checks whether a number (num) is exactly divisible by counter. It is the condition for counter to be a factor of num.
  • print(counter) This is used to display factors of an input number
  • int_num= int(input("Enter a number : ")) This statement asks user to enter a number (int_num) which will be an integer.
  • display_factors(int_num) This calls display_factors number to find the factors of an input number.

You might be interested in
Give an example of an if/else statment and a case statment that are equivalent. Your example should contain at least three choic
zimovet [89]

Answer:

The if - else and equivalent switch case statements in c++ language are given below.

if ( ch == 1 )

       cout << " sum is " << x + y << endl;

   else if ( ch == 2 )

       cout << " difference is " << x - y << endl;

   else if ( ch == 3 )

   {

       cout << " Quitting " << endl;

       exit;

   }

switch( ch )

   {

       case 1 :    cout << " Sum is " << x + y << endl;

                   break;

       case 2 :    cout << " Difference is " << x - y << endl;

                   break;

       case 3 :    cout << " Quitting " << endl;

                   break;

   }      

Explanation:

The above statements use three variables which are declared and initialized as shown.

int x = 10;

    int y = 25;

    int ch;

The above statements execute for of addition, subtraction or to quit the program.

cout << " 1. Addition " << endl;

    cout << " 2. Subtraction. " << endl;

    cout << " 3. Quit " << endl;

    cout << " Enter your choice " << endl;

The variable ch holds the numerical option entered by the user.

    cin >> ch;

For if - else statements, the if statement is executed based on the value of variable ch entered by the user. After execution, the compiler goes out of the statements automatically.

Following the if – else, if any statement is present, it will be executed.

For switch case, every case ends with break keyword. After the required case is executed based on the value of variable ch entered by the user, the break statement is executed which causes the switch case to terminate the control goes out of the statements.

Following the switch case, if any statement is present, it will be executed.

4 0
3 years ago
The part of the computer that contains the brain or central processing unit is also known as
Yuri [45]
Central processing unit (CPU)
4 0
3 years ago
Read 2 more answers
The name of a person their address and their contact information like phone number and email address or consider the minimum inf
andrew-mc [135]

Answer:

false

Explanation:

6 0
4 years ago
_____ is an instruction for a computer to perform a specific task.
alexandr402 [8]
A Command is an instruction for a computer to perform a specific task.
7 0
3 years ago
Use set builder notation to describe these sets.
statuscvo [17]

Answer:

a) S1 = { 2^x | x belongs to the set of Whole Numbers}

b) S2 = { 2+3(x-1) | x belongs to Natural Numbers }

c) S3 = { x^2 | x belongs to the set of Natural Numbers  }

d) S4 = { x | x belongs to English Alphabet }

e) S5 = { x | x is a <em>Vowel</em> of English Alphabet}

Explanation:

Whole Numbers = {0, 1, 2, 3, ...}

Natural Numbers = {1, 2, 3, ...}

English Alphabet={a, b, c, d, e, ... , x, y, z }

Vowels of English Alphabet = {a, e, i, o, u}

8 0
3 years ago
Other questions:
  • 1. What are the two things the base of a number system tells you? After describing these two things, illustrate each with exampl
    6·1 answer
  • Help with number 12 please!
    15·1 answer
  • Create a program that will play the “cows and bulls” game with the user. The game works like this: Randomly generate a 4-digit n
    15·1 answer
  • An AM index between 0 and 1 indicates what? a. the AM signal is very small and will not be detected by the receiver b. distortio
    12·1 answer
  • To save a file so that it can be opened on most computers, select the ____ option.
    10·2 answers
  • Assume the availability of a function called printStars. The function receives an int argument. If the argument is positive, the
    5·1 answer
  • Software engineers typically use UML as a principle means of explaining design. UML stands for:
    12·1 answer
  • Ron is creating building blocks in Word. How can he make the building blocks that he created available?
    8·2 answers
  • Can anyone help and write a sample answer to this please x
    7·1 answer
  • What is the default return type of a method in Java language?
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!