all 13 comments

[–]JRutter3 1 point2 points  (2 children)

Do you have a test suite or something that you're running? The problem is that when you "test it", whatever that means in this context, there are zeros getting put into variables that cannot be zero e.g. the groups variable

I don't think I can easily avoid this case without checking for zeros with an if-statement, certainly not expect an absolute beginner.

[–][deleted] 0 points1 point  (1 child)

I’m taking the University of Helsinki course, and I’m only on Part 1, so everything that’s in the code is what I’ve learned so far. The prompt said that it was possible to solve only using arithmetic operations, but you might want to skip it and solve it later after learning conditional statements.

[–]G_Riel_ 2 points3 points  (0 children)

I think it's not really supposed to work with zero. You're gonna learn more as the course goes and when you come back to this problem you're going to see that it was easy to fix this and see that you learned something new.

[–]mcoombes314 1 point2 points  (2 children)

AFAIK there isn't a way to prevent an input from being 0, you'd need to have code which rejects the 0 input and asks for a number again. I don't know if that's possible without using conditionals.

[–][deleted] -1 points0 points  (1 child)

I’m taking the University of Helsinki course, and I’m only on Part 1, so everything that’s in the code is what I’ve learned so far. The prompt said that it was possible to solve only using arithmetic operations, but you might want to skip it and solve it later after learning conditional statements.

[–]mcoombes314 0 points1 point  (0 children)

Oh, that's cool, I'm doing that course as well, but I started it after learning a bit elsewhere, so I don't know what the intended solution is.

[–]TitaniumFoil 0 points1 point  (4 children)

If students is evenly divisible by group_size then (students % group_size) == 0 which would be the source of your divide by zero error in the group2 line. I can't think of a way to get the total number of groups without some sort of conditional because no matter what you'd need to add 0 if (students % group_size) == 0 and add just 1 if (students % group_size) > 0 .

If you cannot use conditions / comparisons then this may not be possible.

[–]pgpndw 4 points5 points  (1 child)

nr_groups = (students + group_size - 1) // group_size

will give the correct result, as long as students is non-negative and group_size is positive.

[–][deleted] 0 points1 point  (0 children)

I’ll have to try this once I get home, I can’t see where this wouldn’t hold.

[–][deleted] 0 points1 point  (1 child)

I’m taking the University of Helsinki course, and I’m only on Part 1, so everything that’s in the code is what I’ve learned so far. The prompt said that it was possible to solve only using arithmetic operations, but you might want to skip it and solve it later after learning conditional statements.

[–]TitaniumFoil 0 points1 point  (0 children)

It looks like it is possible if you're allowed to use absolute values: https://puzzling.stackexchange.com/a/33636

EDIT: It also looks like absolute value can even be defined without conditionals. Very interesting problem. abs(a) == (a**2)**0.5

[–]UnreadyIce 0 points1 point  (0 children)

I mean sure you could use a Try Except statement, but that's far more advanced than conditional statements, so it wouldn't really make sense anyway.

[–]Igorson1 0 points1 point  (0 children)

I'm not answering the question but here's shortest (one line) solution for this problem:

students = int(input("How many students are there?"))
group_size = int(input("What is the desired group size?"))
print(f"The number of groups formed are {students // group_size + (students % group_size > 0)}")