Cannot figure out problem with random.randint(x,y)

I’m trying to write a program where you think of a number and the computer tries to guess it by going higher and lower but it refuses to work. I’ve narrowed the problem down to line 6 or 7 by trimming bits of the program in and out but I have no idea what’s wrong… Read More Cannot figure out problem with random.randint(x,y)

Appending python dictionary values to a python list

I am trying to process my api result string the result string format is given below. My goal is to add these values to a list where each element of list will be a dictionary. result_str = ‘[‘{"abc.xyz": "80983098429842","dev.uvw": 898420920},’ \ ‘{"abc.xyz": "80983098429843","dev.uvw": 898420921},’ \ ‘{"abc.xyz": "80983098429844","dev.uvw": 898420922}]’ However my code is returning a list… Read More Appending python dictionary values to a python list

Is there a way to check the type of an input, then loop back to the input if the type is incorrect?

def set_values(): loopCtrl = 1 while loopCtrl == 1: loopCtrl = 2 juvenilePopulation = int(input("Enter the population of the juvenile greenfly (1000s) > ")) if not isinstance(juvenilePopulation, int): loopCtrl = 1 juvenileSurvivalRate = float(input("Enter the survival rate of juvenile greenfly (decimal) > ")) if not isinstance(juvenileSurvivalRate, float): loopCtrl = 1 adultPopulation = int(input("Enter the population… Read More Is there a way to check the type of an input, then loop back to the input if the type is incorrect?

Math formula python interpretation

I’ve been trying to convert this math formula into python. So basically the approximation of 1/math.pi. I tried making this iteration with import math N = 132 for k in range(1, N+1): print("The N value is",N , end="\r", flush=True) rec_pi_approximate = (2*math.sqrt(2)/9801) * N * ((math.factorial(4*k) * (1103+26390*k))/((math.factorial(k)**4) * (396**4*k))) But my values have been… Read More Math formula python interpretation