'Write a program using integers user_num and x as input, and output user_num divided by x three times
Write a program using integers user_num
and x
as input, and output user_num
divided by x
three times.
Ex:
If the input is:
2000
2
Then the output is:
1000 500 250
Note: In Python 3, integer division discards fractions. Ex: 6 // 4 is 1 (the 0.5 is discarded).
Here is my code that I have:
user_num = int(input())
x = int(input())
for i in range(3):
user_num/= x
print (int(user_num), end=' ')
I just need to add a end line with the output comes up with 250.
Solution 1:[1]
it's shockingly much simpler than y'all are making it. The program wants a straight forward answer.
user_num = int(input())
x = int(input())
print (user_num // x , user_num // x // x , user_num // x// x // x)
Solution 2:[2]
This is in C but you can see the logic.
#include <stdio.h>
int main(void) {
int userNum;
int x;
int ans1;
int ans2;
int ans3;
scanf("%d", &userNum);
scanf("%d", &x);
ans1 = userNum/x;
ans2 = ans1/x;
ans3 = ans2/x;
printf("%d %d %d\n", ans1, ans2, ans3);
return 0;
}
Solution 3:[3]
''' Type your code here. '''
user_num = int(input())
x = int (input())
i = 0
while i <= 2 :
if i <= 1:
user_num //= x
print(user_num, end= " ")
i += 1
elif i == 2:
user_num //= x
print(user_num)
i += 1
Solution 4:[4]
This should work just fine
user_num = int(input())
x = int(input())
results = []
for i in range(3):
user_num/= x
results.append(str(int(user_num)))
print(' '.join(results))
Solution 5:[5]
user_num = int(input())
x = int(input())
user_num1 = user_num // x
user_num2 = user_num1 // x
user_num3 = user_num2 // x
print(user_num1, user_num2, user_num3)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ACouture |
Solution 2 | Elenie |
Solution 3 | user19202665 |
Solution 4 | |
Solution 5 | Adrian Mole |