Why was floor division used here?
|
Why was floor division used here?
|
|
Jan-30-2026, 05:51 PM
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 // DIMENSIONFloor 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 »
Jan-31-2026, 02:00 AM
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!
|
|
|
Users browsing this thread: 1 Guest(s)
