Relative Content

Tag Archive for pythonfunction

python progam doesn’t proceed from one function to the next

I’m calling 2 functions from 2 different python packages which individually run and finish with exit code 0 without error. However when I call these functions from my main program.py file the first function will run but will not end and proceed to the next function listed.

Python Function Reprinting Prior Input() Contents

secret_word = “hello” guess = “” def get_guess(): guess = input(“Guess: ” ) if guess.isalpha() is not True: print(“Please input a letter”) get_guess() if len(guess) > 1: print(“Please input a single letter!”) get_guess() guess = guess.lower() print(guess) get_guess() Code above for a school project, when reaching the “print(guess)” line, will print all prior content. As […]

how to create and return a dataframe in a function?

I have a function pmi_count_phrase_create() where I input 2 lists want to return a dataframe composed of the lists I create in the function. Problem right now is I am getting a tuple containing the three lists instead.

Why doesn’t my code have the output I want?

def calculate_average_height(height_data): total_height = sum(height_data) average_height = total_height / len(height_data) return average_height def find_closest_height(height_data, average_height): closest_height = min(height_data, key=lambda h: abs(h – average_height)) return closest_height def find_second_closest_height(height_data, closest_height): second_closest_height = min([h for h in height_data if h != closest_height], key=lambda h: abs(h – average_height)) return second_closest_height def main(): city_data = [ {“city”: ‘Ely’, ‘Population”’: 10, […]

Called function adding too many values / Repeating added values

I’m making a blackjack code and having problems with my function. Whenever I call this function, the first time it works and the value is saved but when it appears the 2nd time it adds the first total AGAIN along with the 2nd total.
eg 1st card = 7, total = 7, 2nd card = 3, total = 17 (it should be 10)