Ask Question

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).

+5
Answers (1)
  1. 30 December, 21:19
    0
    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

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “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 ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers