185k views
3 votes
Developed by Frank Vahid. Write a program using integers usernum and x as input, and output usernum divided by x four times. For example, if the input is: 2000 2 where user_num = 2000 and x = 2, then the output must be: 1000 500 250 125 Note: all the values must be printed on the same line. Also, recall that in Python 3, integer division discards fractions. Ex: 6 // 4 is 1 (the 0.5 is discarded).

User NicTesla
by
5.9k points

1 Answer

7 votes

Answer:

Step-by-step explanation:

Let's do this in Python. We will loop through 4 times, each of the loop would compute the dividend, store it as string in a result variable and finally print the result on the same line:

def divide_4_times(user_num, x):

result = ''

for i in range(4):

user_num /= x

result += (' ' + str(user_num))

print(result)

User Rubal
by
7.0k points