[Solved] Why does return not return my Variable?

I think you miss a return in the first function def get_input(high_run, low_run, run): pressed_key = input(”) if pressed_key == “n”: # Next Page return set_high_run_np(high_run, run), set_low_run_np(low_run, run) def set_high_run_np(high_run, run): if high_run != len(ldata): high_run = high_run + run return high_run def set_low_run_np(low_run, run): if low_run != len(ldata) – run: low_run = low_run … Read more

[Solved] Why do I get this error in Python?

return print(char) This will first print the value of char (as in print(char)) and then try to return the return value of the print function. But since the print function always returns None—it only prints the value, it does not return it—your function will always return None causing the error when trying to concatenate None … Read more

[Solved] What does x ^ 2 mean? in python

It doesn’t ‘mean’ anything, not to Python; it is just another character in a string literal: “Enter the value for the co-efficient of x^2. ” You could have written something else: “Enter the value for the co-efficient of x to the power 2. ” and nothing but the output shown when asking for input() would … Read more

[Solved] Access the key of a multilevel JSON file in python

You can use next with a generator comprehension. res = next(i[‘name’] for i in json_dict[‘ancestors’] if i[‘subcategory’][0][‘key’] == ‘province’) # ‘Lam Dong Province’ To construct the condition i[‘subcategory’][0][‘key’], you need only note: Lists are denoted by [] and the only element of a list may be retrieved via [0]. Dictionaries are denoted by {} and … Read more

[Solved] How to use a function after definition?

Clearly speed is a parameter for the function, so pass it to the function as an argument, not via a global variable. def journey(knots): ”’Convert knots to kilometres per day”’ return round(knots * 1.852 * 24) >>> speed = 5 # in knots >>> print(“Ship travels {} kilometres in one day”.format(journey(speed))) Ship travels 222 kilometres … Read more

[Solved] Python get info from long complicated string

You can use re module for the task: style=”fill: rgb(0, 0, 0); fill-opacity: 1; font-family: ProjectStocksFont; font-size: 70px; font-weight: normal; font-style: normal; text-decoration: none;” import re print( re.search(r’font-size:\s*(\d+)’, style)[1] ) Prints: 70 3 solved Python get info from long complicated string