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
denis23 [38]
3 years ago
4

LAB: Divide input integers

Computers and Technology
1 answer:
Brums [2.3K]3 years ago
7 0
Mark Brainliest please


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
Question 9/10
Firlakuza [10]
They sometimes offer free service
5 0
3 years ago
Read 2 more answers
Digital manufacturing has impacted our world today! List a reasons why.
Maru [420]
Because we can get manufacturing faster than usual
6 0
3 years ago
I have six nuts and six bolts. Exactly one nut goes with each bolt. The nuts are all different sizes, but it’s hard to compare t
juin [17]

Answer:

Explanation:

In order to arrange the corresponding nuts and bolts in order using quicksort algorithm, we need to first create two arrays , one for nuts and another for bolts namely nutsArr[6] and boltsArr[6]. Now, using one of the bolts as pivot, we can rearrange the nuts in the nuts array such that the nuts on left side of the element chosen (i.e, the ith element indexed as nutArr[i]) are smaller than the nut at ith position and nuts to the right side of nutsArr[i] are larger than the nut at position "I". We implement this strategy recursively to sort the nuts array. The reason that we need to use bolts for sorting nuts is that nuts are not comparable among themselves and bolts are not comparable among themselves(as mentioned in the question)

The pseudocode for the given problem goes as follows:

// method to quick sort the elements in the two arrays

quickSort(nutsArr[start...end], boltsArr[start...end]): if start < end: // choose a nut from nutsArr at random randElement = nutsArr[random(start, end+1)] // partition the boltsArr using the randElement random pivot pivot = partition(boltsArr[start...end], randElement) // partition nutsArr around the bolt at the pivot position partition(nutsArr[start...end], boltsArr[pivot]) // call quickSort by passing first partition quickSort(nutsArr[start...pivot-1], boltsArr[start...pivot-1]) // call quickSort by passing second partition quickSort(nutsArr[pivot+1...end], boltsArr[pivot+1...end])

// method to partition the array passed as parameter, it also takes pivot as parameter

partition(character array, integer start, integer end, character pivot)

{

       integer i = start;

loop from j = start to j < end

       {

check if array[j] < pivot

{

swap (array[i],array[j])

               increase i by 1;

           }

 else check if array[j] = pivot

{

               swap (array[end],array[j])

               decrease i by 1;

           }

       }

swap (array[i] , array[end])

       return partition index i;

}

7 0
3 years ago
What are two type of physicals connection
netineya [11]
Two types of physical connection are:

A wired connection using a cable

A wireless connection using radio waves
7 0
4 years ago
The default _____ color is set when you type text.
Elenna [48]
The default hyperlink color is automatically set when you type
5 0
3 years ago
Other questions:
  • When Aaron was called for an interview at a graphic designing company, his first interview test assessed his creativity and his
    7·2 answers
  • Which view In a presentation program displays you’re slides in full screen modes ?
    8·2 answers
  • What is the name of the program that takes high-level code and transforms it into machine-level code?
    8·1 answer
  • Suppose you have an int variable called number. What Java expression produces the second-to-last digit of the number (the 10s pl
    15·1 answer
  • Select the recommended design practice that applies to a web site using images for main site navigation.
    7·1 answer
  • What is one purpose of an essay’s conclusion paragraph?
    13·1 answer
  • Missy loves her old Windows games. When she upgrades her Windows system, the games run fine, but the output looks fuzzy since th
    15·1 answer
  • What are your thoughts on copyright?<br><br> (Write 2 or more sentences)
    9·2 answers
  • Ania has written this SimpleStopwatch class. In which line is she measuring the elapsed time?
    13·1 answer
  • Which two peripherals are not required to browse the internet?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!