i started learning how code, , i've been assigned problem i've been stuck on many hours , hoping receive hints @ least solve problem. main point of exercise practice division , modulus. can use basic statements, nothing fancy conditionals or since haven't gotten point.
i need user input # 1 - 25, , program let them know unit , row number in. i've managed code working rows, cannot figure out how unit number.
here's code:
shelfnumber = int(raw_input('what shelf number? ')) row = int(shelfnumber / 5.1) + 1 unit =
i've tried lot of things unit, none of them worked out, left blank. appreciate hints can give me. thank help.
edit: realized should try , @ least show ideas i've tried. if regular modulo # % 5, works multiples of 5 way on right. i've tried implementing row #'s each # has haven't gotten anywhere either. i've tried similar dividing decimal, casting int, using modulo failed, etc., etc.\
edit: sorry, realized uploaded wrong image.
this problem easier if countrd 0 instead of 1. is, if row , unit numbers 0 4 instead of 1 5 , if input value 0 24 instead of 1 25.
in case, we'd write:
row = shelfnumber / 5 unit = shelfnumber % 5
since starts ftom 1 ("is one-indexed" in usual jargon), shelfnumber
1 bigger formula needs, , need make row
, unit
1 bigger computed.
but there's no trouble fixing that:
row = (shelfnumber - 1) / 5 + 1 unit = (shelfnumber - 1) % 5 + 1
in python 3, you'd need write //
insted of /
, , work reasonably recent python 2.
Comments
Post a Comment