# # The rice problem # --- from an old legend # # Matt Bishop, MHI 289I, Winter 2018 # nsq = 64 # number of squares on chessboard # # start with 1 grain of rice on the first square # total = 1 rice = 1 print "%20d grains on square %2d; total rice %20d" % (rice, 1, total) # # now loop to do the others # for i in range(2, nsq+1): # double the grains at each iteration rice = rice * 2 total = total + rice print "%20d grains on square %2d; total rice %20d" % (rice, i, total)