[Python] Share and the rest - Cloud LEVEL Problem Difficulty 1

Asked 2 years ago, Updated 2 years ago, 22 views

Enter two positive integers and divide the number you entered by the number you entered later Write a program that outputs the quotient and the remainder in order.

Enter: a, b
output: Divide a by b, and then divide a by b by the rest

It runs well and the test case works well, but it says wrong answer. The round prevents the same output as 5.0 when the integer is divided. I don't think there's a mistake in the blank, so what's the problem? I'd appreciate your help.

First used code

a, b = input().split() #Input
a = int(a) #Convert to an integer
b = int(b) #Convert to an integer
print(round(a/b), end=' ') #Output with no line break
print(a%b) #Output

Second used code

a, b = input().split() #Input
a = int(a) #Convert to an integer
b = int(b) #Convert to an integer
print(str(round(a/b)) + " + str(a%b)) #Output

python

2022-09-20 18:04

2 Answers

Do not play round().
Divide 7 by 2, the quotient is 3 and the remainder is 1, but round (7/2) = round (3.5) = 4.

So what should we use instead of rounding up? Try again from here.


2022-09-20 18:04

a, b = input().split()
a = int(a)
b = int(b)
total_1 = int(a/b)
total_2 = int(a%b)
print(str(total_1) + " " + str(total_2))

I was thinking it was too hard. Thank you!


2022-09-20 18:04

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.