Month: November 2018

How to stop a Python function from going below 1

I’d written a function to take a given number, then reduce it by half for x iterations. Problem was with some numbers it’d go past the limit of 64 bit subscripts and error out. This came out of something I’d read where if you keep reducing the distance you travel by half you’d never reach your destination. It’s funny what I read ends up as functions in this python app I’ve written.

I had some error checking built in. But then I thought, why not just check if the end result is greater than or equal to 1. That solves it – it never gets into the weeds this way. Perfect.

Here’s the code:

def byhalves(): # A thought experiment .
a=float(input(“Enter a number to halve until errors out:”))
t=int(input(“Enter number of iterations:”))
print(“Be prepared, halving a distance means you’ll never reach it.”)
try: # What you’ll find is pretty much any number will never reach zero by half
while i<t:
b=a/2 # Took out the natural log. For the purposes
# of this app it’s worthless.
if b>=1:
print(“Out of range at final result one.”)
a=b # Now make a equal to the last result. And iterate on.

print(“Exceeds maximum allowable exponents.\nTry again with fewer iterations or index.”)
filw.write(‘Termination of By Halve Function.\n’)#for logging of module term
filw.write(ctime(time()))#with full timestamp

if you don’t know Python I’ll break it down:
1. def byhalves() – this is setting up the function byhalves.
2. i=0 – this is the index initialized to zero
3. a=float(input(“Enter a number to halve until errors out:”))- input a floating point value and store in the variable a.
4. t=int(input(“Enter number of iterations:”)) – the index you’ve chosen in integer form. Stored as variable t
5. the print is obvious – it puts it on screen.
6. try: – this is the error catcher. Right now this is coupled with except statement toward the bottom that uses a print statement to tell you that you’ve blown past the max number for exponents.
7. while i<t: – this is a while loop where the index is compared to the number you entered and stored as variable t.
8. i=i+1 which I could abbreviate as i++ This increments the index value.
9. b=a/2 – this takes the valuable stored as a and divides it by 2 or half. Then stores it in variable b.
10. if b>=1: – so long as the b or displayed variable doesn’t go below 1 we’re good.
11. print(“a=”,a,”\t\tb=”,b,”\t\tindex=”,i) – so everything in Python 3.4 you have to wrap in parentheses and quotation marks. In this line you see I put labels a=, b= and so on. The commas separate the quotes from the variable and so on so they all appear on the same line. And you’ll see some \t’s in there – those are tab escape codes.
12: else: The if/else clause terminator.
13. The next line of the else: prints Out of range af final result one.
14: The terminator of the try: clause is except: and this one triggers on ValueError which you get when you blow past the max number of exponents.
15: Prints Exceeds maximum allowable exponents then on the next line(That’s the \n) says to try again with fewer iterations or index.
16: Anything that begins filw.write – thats logging for this function.
17: ctime(time()) – that gives time in normal format for time stamp logging.
18: return() – returns to the main body of the program.

**DISCLAIMER** to properly use this you need the time and math libraries imported.

The trouble with MD’s

Recently someone had to see a new MD regarding high blood pressure. I’m on the fence if I should identify this doctor because he’s the attending for a practice in the area.

One of the prime reasons that I as a general principle distrust MD’s is because I’ve caught them out with their what I term lies.

For example, someone was told by the doctor that carbs were ok because we need them for quick energy, that he could have a potato or rice. And that when the A1C number drops from 9 to 6.2 that you’re still diabetic, not pre-diabetic. It’s enough to make me angry and make me question the ability of doctors to consistently say the wrong fucking thing.

This doctor also said that eating one meal a day resets the metabolism and lowers it. Someone said if that that were the case, the Jews who were released from the Nazi concentration camps would look like Beluga Whales instead of the emaciated messes that they were.

This doctor also put him on medication for the high blood pressure. But here’s the thing, the doctor was dismissive of the other factors that can raise blood pressure, like lack of sleep, agitation, anxiety, dehydration etc. Even the Nurse Practitioner said dehydration can raise blood pressure. Couple it with a few of the other factors I mentioned and well you can see my concern.

This doctor had the temerity to say to put someone’s health care in the doctors hands. I’ll use the Latin for this one Ut Si.

Then of course there’s the persistent myth that fats are bad for us. That sugar is ok – so tell me why we’re seeing increased rates of Type II diabetes and still it seems as many heart attacks, strokes, etc. We were told a big fat lie by a doctor.

I note too doctors have become more pill pusher than anything else. I think we can blame that on the pharma industry. I mean lunches, trips all over creation, etc. Really?

Because we’ve been on a low/no carb/sugar diet and losing weight and seeing someones A1C drop lower and lower.

I suppose we’re both a doctors worst nightmare – informed patients.

When it Comes to Good Meat

Some time back I’d posted how the nearby Joe’s Meat Market. Today I was tasked to go in and get some skin on bone in chicken thighs and some slab bacon cut nice and thick.

The deal 10lbs of skin on bone in chicken thighs were $12. That works out to $1.20 a pound for one of the best parts of chicken you can get. And they’re super easy to de-bone – two lateral cuts, one scrape under with good shears and one just pulls the bone out of the thigh. The bones of course have a little meat on them so they get saved to make soup later on.

Yesterday I got two ribeye steaks – cut about an inch or so thick. That was more pricey but I’ll say something – usually you end up with a lot of gristle with steaks like that you might purchase at a supermaket (Or is that supermercado?) In fact I think the quality of the steaks is what caused an order to get the chicken at the same place.

Plus it supports a local business. It saddens me to see the number of local places that have shut down over the years. But this market seems to be going strong. Hopefully it’ll be going strong for years to come.

And we’re going to be eating chicken thighs for awhile I guess.