return-value

Python: rest of code not playing out when function returns True

Python: rest of code not playing out when function returns True Question: I am coding a trivia game. When the player gets the question correct, the askQuestion function returns True, and the playGame function (which calls upon the askQuestion function) is supposed to add 1 point to the score. However, the score never increases. I …

Total answers: 2

Returning a value based on index number of each element in a list

Returning a value based on index number of each element in a list Question: I am trying to identify the first element, last element, and other elements in a python list using a function. If it’s the first element, I want 0 to be returned, if it’s the last element I want -1 to be …

Total answers: 1

Python return statement not returning correct output

Python return statement not returning correct output Question: I have a simple function to return True or False when a condition is met. But the return statement is not functioning as I expected. Could anyone help me out to point out the mistake I am making. graph = { ‘f’: [‘g’, ‘i’], ‘g’: [‘h’], ‘h’: …

Total answers: 2

Function does not return value when used with decorators

Function does not return value when used with decorators Question: When I call the function without the decorator a list of all files with the matching extension is returned. However, if I add the decorator @get_time, I do not get a return value from the function. def get_time(func): from time import perf_counter from functools import …

Total answers: 2

Python Return Statement Not Providing Expected Results

Python Return Statement Not Providing Expected Results Question: Just attempting to return values from a defined function. When calling the function first and attempting to print the return values I receive "[variable] not defined". However, if I run "print(qb_stat_filler())" it prints the results in a tuple. I need the individual variables returned to use in …

Total answers: 1

and/or instead of if/else

and/or instead of if/else Question: After working through some toy examples, I could see that it’s possible to emulate the ternary operator of "c" condition?value_if_true:value_if_false in Python using condition and value_if_true or value_if_false. I would like to know if it works in all cases and if it is better or worse than using value_if_true if …

Total answers: 1

How to get the return value of a function in multiprocessing in Python

How to get the return value of a function in multiprocessing code Question: This is my python code. I am trying to get the returned value(aa1) from the print_cube() Is there a way to get the value of aa1 inside the main(). I have to use multiprocessing to call other functions also. import multiprocessing def …

Total answers: 2