'if' statement only accomplished only once in a loop

I am simulating a cache system by performing a cumulative sum of bytes and, when this sums up to 0.95 the size of the cache, forces the value to be 0.9 of the full size.

Final result should evolve as a saw tooth.

This is the code I implement to force this condition.

cache_size=1e11 #B 
for i in range(1,rows_number):

And this is the output.

Simulation output

How does the if statement is only accomplished once in the loop?

Asked by: Maria846 | Posted: 06-12-2021

Answer 1

Given the code, I don't see why the observed behavior is wrong. This is how you are capping the cumulative sum:


You are scaling the value by low_mark factor and not actually capping it. So it is possible that it goes beyond the cache size. You probably intend to do:


Also, I don't see where ordered_datestamp['file_size_Cum'][0] is initialized. You are initializing ordered_datestamp['Cache']=0 which is weird as ordered_datestamp['Cache'] seems to be a list.

Answered by: Caroline813 | Posted: 07-01-2022

Similar questions

python - How would a system tray application be accomplished on other platforms?

Windows has the "system tray" that houses the clock and alway-running services like MSN, Steam, etc. I'd like to develop a wxPython tray application but I'm wondering how well this will port to other platforms. What is the tray equivalent on each platform, and how much manual work would be required to support Windows, OSX and Linux (which shells in particular would be friendliest).

Python + ZMQ: Operation cannot be accomplished in current state

I am trying to get a python program to communicate with another python program via zeromq by using the request-reply pattern. The client program should send a request to the server program which replies. I have two servers such that when one server fails the other takes over. Communication works perfect when the first server works, however, when the first server fails and when I make a request to the second server,...

python - Pillow, centering of text not working, how is this accomplished?

I have tested the calculations and the math is correct (and takes into account the height and width of the font), but after Python creates the image and I put it into Photoshop, the vertical and horizontal centering of the text is not correct. Should I be doing something else with my code? from PIL import Image, ImageDraw, ImageFont # base = Image.open("Images/Phones/KK17018_Navy_KH10089.jpg").con...

Still can't find your answer? Check out these communities...

PySlackers | Full Stack Python | NHS Python | Pythonist Cafe | Hacker Earth | Discord Python