129k views
4 votes
g 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 Ionel Lupu
by
6.3k points

1 Answer

3 votes

Answer:

The python program to this question as follows:

Program:

usernum= 2000 #define variable usernum and assign value

x=2 #define variable x and assign value

result = '' #define variable result

for i in range(4): #loop for calculate value

usernum =usernum//x #divide value

result += (' '+str(usernum)) #collect value

print(result) #print value

Output:

1000 500 250 125

Step-by-step explanation:

In the above python program code firstly, two integer variable is defined that is "usernum and x" in which variable usernum holds a value that is "2000" and variable x holds a value that is "2", and a string variable result has defined, that store the calculated values.

  • In the next step, a for loop is declare that runs four times, in which the usernum variable divides its value by variable x and stores all the values in string variable result.
  • In the last print, function is used to print result variable value.
User Mpro
by
6.2k points