what is the question? How much rent a group of N students must pay, given the surcharge, or the number of rooms required?

To determine the number of rooms needed, why not use the '\' operator. For instance, if 11 = 2 * 5 + 1, then 11 % 5 = 1, and 11 \ 5 = 2.

If we have 1, 2, 3 or 4 students, we need 1 room. Unfortunately, students \ 4 will yield the reaults 0, 0, 0, 1. However, studens 0, 1, 2, 3 \ 4 will give 0 in all cases. That is not 1, but it is equal for all the nr of studens.
So, what do we get when we first subtract 1 from the number of students, and THEN do the '\4' operation?
We get:
nr of st. nr of rooms (students - 1) \ 4
1, 2, 3, 4 0
5, 6, 7, 8 1
9, 10, 11, 12 2

Not quite correct, but close. Can you make it perfect?

jon ninpoja

Ranch Hand

Posts: 424

3

posted 3 months ago

Just to make sure we on the same page

A room has 4 beds...so if 5 students pitch up
There is a surcharge on 3 beds / night

Piet, did you mean to use a forward slash rather than a backslash in your reply?

Jon, one of the things that changed from legacy python (v2) to modern python was division of integers using a single slash. Since your previous posting of code appears to be modern python, I will focus on the modern python way.

Integer division using a single slash in modern python always results in a float, not an integer. For example, not 0. To get an integer result use the integer divide operator "//" The same example with the integer divide operator:

The modulo operator works the same in both versions of python. and However, to tie it back to your problem, the modulo operator is calculating the number of occupied beds in the room.

Grrr. whereas Using Idle or Jupyter is an easy way to test code snippets. (I should have used copy and paste rather than try to type it from memory.)

Piet Souris

Master Rancher

Posts: 3080

108

posted 3 months ago

Travis Risner wrote:Jon, first a question for Piet.

Piet, did you mean to use a forward slash rather than a backslash in your reply?

Ahhh, messed up here. I meant integer division (so 1 / 4 = 0), but I screwed up and I forgot that this is about Python and not Java. Thanks for correcting me.

@Jon
the idea is to determine the required number of rooms first, then you know how many beds there are, and given the number of students: voilà. But I seem to be facing a lesser period nowadays (messing up a lot lately), I leave you to the safe hands of Travis.

All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad: