# 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)

# Python: Want to have something taken out of a list how do I do this in python 3?

Here is my code if that helps you answer the question import random Exlist = [‘pl1’, ‘pl2’] Exvar = random.choice(Exlist) print(Exvar) Exlist = Exlist – list(Exvar) I tried changing Exvar to a list >Solution : Use remove(). For example, import random Exlist = [‘pl1’, ‘pl2’] Exvar = random.choice(Exlist) print(Exvar) Exlist.remove(Exvar)

# 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

# program to find fibonacci sequence of a number

how do i find the fibonacci sequence of a number . Here Is The code def fib(n): for i in range(n): b = 1 b+=i print(b) p = fib(9) the program just returns the normal sum. how to do this in the easy way >Solution : The fibonacci sequence is built by adding the last… Read More program to find fibonacci sequence of a number

# is there a way to make an array of words in python?

i am a beginner in python my wish is to make an array of n lines and n rows. I have a dictionnary of words and i need to put them in an array n*n . provisions ={‘cake’:’20’,’eggs’:’10’,’tomatoes’:’4′,’potatoes’:’2′,’bread’:’4′} | / | 1 | 2 | |:—- |:——:| —–:| | 1 | cake | eggs |… Read More is there a way to make an array of words in python?

# Can a linked list class in python take a 'next' value in the constructor?

For convenience, I’d like to use a linked list Node class like the following: a = Node(3) b = Node(2, a) c = Node(1, b) # c = (1) -> (2) -> (3) I’ve tried the following class definition class Node: def __init__(self, val: int, next_node: Node = None): self.val = val self.next = next_node… Read More Can a linked list class in python take a 'next' value in the constructor?

# Is there any way to make an element in a list equal all integers?

I am trying to get these two list to equal one another: a = [None, 3, 4, 5, 8, 9, None, 0, -3, 2, None, None, None] b = [0, 3, 4, 5, 8, 9, 0, 0, -3, 2, 0, 0, 0] if a == b: print("yay or sth") Currently I have None as a… Read More Is there any way to make an element in a list equal all integers?

# How to split or remove excess letters/objects in python

output ==> [‘s’, ‘t’, ‘u’, ‘f’, ‘w’, ‘x’, ‘y’, ‘y’] this is the output I get, how can I get rid of one of the y letters? >Solution : You can use the remove() method of the list to remove a specific element by its value. For example: output = [‘s’, ‘t’, ‘u’, ‘f’, ‘w’,… Read More How to split or remove excess letters/objects in python

# 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