Python Forum
Why was floor division used here?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why was floor division used here?
#1
Question 
   

512 / 8 = 64

Is this a good practice or something? Thank you in advance.
Reply
#2
Please don't post your Python code as an image file. Read this help topic to learn how to format your code in this forum.
WIDTH = HEIGHT = 512
DIMENSION = 8
SQ_SIZE = HEIGHT // DIMENSION
Floor division is used here because it returns an integer (int type) instead of a floating number (float type). We want SQ_SIZE to be an integer.
>>> 512 / 8
64.0
>>> 512 // 8
64
« We can solve any problem by introducing an extra level of indirection »
Reply
#3
Quote:Why was floor division used here?

To get a neat fit!

# start with an approximate size
approx_chess_board_side = 529
num_squares_per_side = 8
individual_square_size = approx_chess_board_side // num_squares_per_side
print(f'Make the chess board sides {8 * individual_square_size}, then everything fits neatly.')
Why not start with the individual squares?

# start with the individual squares 
units = 'inche(s)'
one_square_side = 2
chess_board_side = 8 * one_square_side
frame_width = 1
print(f'The chess board will be {chess_board_side} x {chess_board_side} {units} square, with a frame of  {frame_width} {units} around it.')
print('All inlaid with gold filaments and finest blue-green and mutton-fat-white jade from 新疆和田!')
Price by consultation!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Division Mallard 9 890 Dec-17-2025, 03:47 PM
Last Post: Mallard
  division error nathanael 2 776 Dec-12-2025, 11:55 PM
Last Post: deanhystad
  Get numpy ceil and floor value for nearest two decimals klllmmm 4 4,895 Jun-07-2023, 07:35 AM
Last Post: paul18fr
  Division questions Dionysis 5 3,605 Feb-14-2023, 02:02 PM
Last Post: Dionysis
  Floor approximation problem in algorithm gradlon93 3 2,329 Dec-14-2022, 07:48 PM
Last Post: Gribouillis
  Division by zero and value of argument Lawu 5 10,682 Jul-01-2022, 02:28 PM
Last Post: Lawu
  Floor division problem with plotting x-axis tick labels Mark17 5 4,772 Apr-03-2022, 01:48 PM
Last Post: Mark17
  Division calcuation with answers to 1decimal place. sik 3 3,557 Jul-15-2021, 08:15 AM
Last Post: DeaD_EyE
Photo Locate Noise floor level for a spectral data in Python Ranjan_Pal 1 4,773 Dec-19-2020, 10:04 AM
Last Post: Larz60+
  Floor division return value Chirumer 8 7,826 Nov-26-2020, 02:34 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020