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
Leya [2.2K]
3 years ago
11

Write a program using integers userNum and x as input, and output userNum divided by x three times.

Computers and Technology
1 answer:
andrezito [222]3 years ago
7 0

Answer:

# The user is prompted to enter number as dividend

# The received number is assigned to userNum

userNum = int(input("Enter the number you want to divide: "))

# The user is prompted to enter number as divisor

# The divisor is assigned to x

x = int(input("Enter the number of times to divide: "))

# divideNumber function is defined to do the division

def divideNumber(userNum, x):

   # counter is declared to control the loop

   counter = 1

   # the while-loop loop 3 times

   # the division is done 3 times

   while counter <= 3:

       # integer division is done

       # truncating the remainder part

       userNum = userNum // x

       # the result of the division is printed

       print(userNum, end=" ")

       # the counter is incremented

       counter += 1

# the divideNumber function is called

# the received input is passed as parameter

# to the function

divideNumber(userNum, x)

# empty line is printed

print("\n")

Explanation:

The // operator in python works like the / operator in C. The // operator returns only the integer part of division operation. For instance 6 // 4 = 1. The fraction part is discarded.

You might be interested in
g Write a program that prompts the user for an integer n between 1 and 100. If the number is outside the range, it prints an err
grin007 [14]

Answer:

The cpp program is given below.

#include<iostream>

#include<iomanip>

using namespace std;

int main() {

   

   // variables declared

   int n;

   int sum=0;

   float avg;

   

   do

   {

       // user input taken for number    

       cout<< "Enter a number between 1 and 100 (inclusive): ";

       cin>>n;

       

       if(n<1 || n>100)

           cout<<" Number is out of range. Enter valid number."<<endl;

       

   }while(n<1 || n>100);

   

   cout<<" "<<endl;

   

   // printing even numbers between num and 50  

   for(int num=1; num<=n; num++)

   {

       sum = sum + num;

   }

   

   avg = sum/n;

   

   // displaying sum and average

   cout<<"Sum of numbers between 1 and "<<n<<" is "<<sum<<endl;

   cout<<"Average of numbers between 1 and "<<n<<" is ";

   printf("%.2f", avg);

   

       return 0;

}

OUTPUT

Enter a number between 1 and 100 (inclusive): 123

Number is out of range. Enter valid number.

Enter a number between 1 and 100 (inclusive): 56

 

Sum of numbers between 1 and 56 is 1596

Average of numbers between 1 and 56 is 28.00

Explanation:

The program is explained below.

1. Two integer variables are declared to hold the number, n, and to hold the sum of numbers from 1 to n, sum. The variable sum is initialized to 0.

2. One float variable, avg, is declared to hold average of numbers from 1 to n.

3. User input is taken for n inside do-while loop. The loop executes till user enters value between 1 and 100. Otherwise, error message is printed.

4. The for loop executes over variable num, which runs from 1 to user-entered value of n.

5. Inside for loop, all the values of num are added to sum.

sum = sum + num;

6. Outside for loop, average is computed and stored in avg.

avg = sum/n;

7. The average is printed with two numbers after decimal using the following code.

printf("%.2f", avg);

8. The program ends with return statement.

9. All the code is written inside main() and no classes are involved.

3 0
3 years ago
Why is image compression an important part of vidoetechnology?
OLEGan [10]

Answer: Image compression is the technique which is responsible for the reduction in the size of the image according to the need of the video technology. Image compression is done because of the following reasons:-

  • Makes more space for the storage and creates space.
  • It also reduces the time that is used up for the uploading of the video through internet.
  • Text, labels etc might also be needed to inserted along with the image .

4 0
3 years ago
In Microsoft word, when you highlight existing text you want to replace, you are in
jeka57 [31]
I think that would be the stages of deletion bro.

Hope it helps
5 0
3 years ago
Read 2 more answers
Which of the following is Tynker an example of?
larisa [96]

Answer:\

Integrated Development Environment

hope it help

5 0
2 years ago
Read 2 more answers
A customer calls you and states that her laptop screen is very dim. In order to avoid going to the client's site, which of the f
wel

it depends on the brand of laptop,If it is standard use function key if not None of the above

7 0
3 years ago
Other questions:
  • Which keyboard feature is a form feed character?
    14·1 answer
  • Marie uses a browser to visit a blog. What is the unique identifier of the blog?
    13·2 answers
  • A series circuit and identify how voltage is split up by each load in the circuit?
    11·1 answer
  • What are the three major functions of a game engine?
    15·1 answer
  • A group of accountants encrypt the emails they send to your company because they contain highly sensitive financial information.
    11·1 answer
  • DO MOBILE DEVICES HAVE TO WORK IN LIMITED SCREEN SPACE
    11·2 answers
  • Celeste is writing a paper. However, two pages in, her computer shuts down unexpectedly. She never saved her paper, and all her
    12·2 answers
  • Vegetable farming is a good source of income explain this statement<br>​
    5·1 answer
  • 1.5 question 3 on edhesieve
    6·1 answer
  • Write a statement that calls the recursive method backwardsAlphabet() with parameter startingLetter.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!