#๐Ÿ”’ A little push

32 messages ยท Page 1 of 1 (latest)

left roost
#

Please write a program which asks for the number of students on a course and the desired group size. The program will then print out the number of groups formed from the students on the course. If the division is not even, one of the groups may have fewer members than specified.
This is a question of mooc 2026 program in the part where i am at **we have not done if/else conditional statements **which i know but dont want to use as question says

  • "If you can't get your code working as expected, it is absolutely okay to move on and come back to this exercise later. The topic of the next section is conditional statements. This exercise can also be solved using a conditional construction."*

Anyways,

n2 = int(input("Desired group size? "))
grps = n1//n2+ n1%n2
print(f"Number of groups formed: {grps}")```
This is as far as i was able to think i also tried n1//n2+ n1%n2/n1%n2 but the problem here is it will be 0/0 error whenn modulo is zero and i am blank ahead
hardy boughBOT
#

Hey @left roost!

Please edit your message to use a code block

Add a py after the three backticks.

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
#

@left roost

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

obtuse tree
#

it's lacking context. Are you allowed to use the math module?

left roost
#

no

#

its like part 1 of the course and we have not had bolean logic or if/else

obtuse tree
#

!e ```py
n1 = 19

for n2 in range(1, 6):
print(n1, n2, -((-n1)//n2))

hardy boughBOT
obtuse tree
#

this is a sneaky way to do "ceildiv"

left roost
obtuse tree
#

because flooring with negative numbers makes the absolute value larger

obtuse tree
#

it divides then rounds towards negative infinity

left roost
#

yeah i know that

obtuse tree
#

the ceiling is the opposite of the floor

left roost
#

ah but can we make this without using range as its even more advanced than conditional statements

obtuse tree
#

I didn't use range to solve your problem

#

I used range to show the answer for various n2

#

-((-n1)//n2) this is the solution

left roost
#

oh i dont know what that does so i thought it was required thanks

obtuse tree
#

negating, floordiv-ing, then negating again

#

therefore getting the opposite effect of flooring

left roost
obtuse tree
#

I'm confused by your question

left roost
# obtuse tree I'm confused by your question

like do we usually use something like this when we hae to round up or its something i have to develop the thought process for like in maths there are some standard questions that you should know to do them?

obtuse tree
#

no we would use math.ceil

coarse isle
#

I think that's more of a math thing than a logic thing. I've never had to do anything like that before

obtuse tree
#

this is for rounding up and dividing, at the same time, as a little trick

#

because you can't use anything else in your question

left roost
#

thanks for the quick response and help

hardy boughBOT
#
Python help channel closed using Discord native close action

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.