All Questions
Tagged with python-3.x function
3,157
questions
0votes
0answers
16views
Function printing my 'else' without fulfilling the condition [duplicate]
im having trouble with the function bellow where i need to check if the 'key' input is already in the function parameter. only if the 'key' is already in the parameter that is passed my else should be ...
-2votes
0answers
20views
Decorator of recursive function [closed]
What is the difference between calling func(*args, **kwargs) in decorator of recursive function and calling value=func(*args, **kwargs)? I thought it is the same thing but now I have doubts about it. ...
0votes
1answer
28views
Getting 'TypeError: concatenate_all() takes 0 positional arguments but 3 were given'
I'm new to python and I'm currently styding it, more specifically how to create functions; in this piece of code, I'm supposed to create a function that concatenates all of the arguments given in a ...
0votes
0answers
15views
Python: Function Error TypeError: tuple indices must be integers or slices, not tuple & TypeError: 'int' object is not subscriptable
Have been applying below code on my function, but regularly getting an error. Please can you explain where am i going wrong
clusters = np.zeros((len(dataset),1))
def assign(centroids,dataset,clusters,...
1vote
0answers
25views
Own lru_cache decorator in python
I can't understand, why my own decorator "lru cache" doens't work.
def cache(max_size: int):
dictionary = OrderedDict()
def trace(func):
@functools.wraps(func)
...
0votes
0answers
4views
How does a Python Interpreter execute global variable declarations?
I'm working to complete a code challenge, where the goal is to create basic arithmetic from just functions. I'm working from a Python 3.8 Interpreter (EMACS Terminal)
Example, seven(times(five())) ---&...
-1votes
0answers
19views
What is the purpose of positional parameter? [closed]
What is the purpose of positional parameters in Python? Like if you don't want an input from the user and you want to perform operations on a value of any data type, you can just create it inside the ...
0votes
0answers
5views
How to remove a file when a reminder is removed
So this is like a database, the user needs to be reminded by the reminder shown in the program entered by the other user. My question is, how will I be able to delete or remove the file of the ...
-3votes
0answers
13views
Can I implement this complicated function in python : require integral inside a fuction [closed]
i want to implement this function in python, except y, all other variable is constant
enter image description here
-2votes
0answers
19views
Divide Integers In Unequal random Integers (Python Programming) [closed]
Q: Randomly divide an integer n into x parts, make sure that each part is an integer and conditions should be:
new part >= n/2x, and
new Part <= 2n/x,
Please write a function to output the ...
-1votes
0answers
25views
NameError: name 'mergeTwoLists' is not defined
I have to functions defined inside a class. When I go to call the first function inside the second function it says that it is not defined and gives me the following error:
NameError: name '...
0votes
1answer
13views
write your pay computation with time-and-a-half for overtime and create a function called computepay which takes two parameters (hours and rate)
For the above question i have written this code . Math formula is correct but it is not giving the correct answer where is the fault?
def computepay(hours, rate):
if hours<=40:
pay = ...
0votes
1answer
15views
Python functions calling functions inside functions
In Python, say I have the following code:
def func0():
print("This is func0")
def func1():
print("func1 calls func0")
func0()
def func2():
def func21():
...
0votes
2answers
47views
How can I create a Pause function inside a class and then use it inside turtle game?
I was working on a snake game using turtle graphics in python. The game worked well.
Then, I wanted to improve on it and add a pause function to it. When I just wrote the lines of code for the pause ...
1vote
1answer
29views
Decorators for recursion function
I want to write a decorator that will compute runtime of function that compute fibonachi number of 5(fib(5)) 10 times and will print a medium runtime value. But my decorator returns an error. How to ...
0votes
0answers
6views
I wanted sigup button to give the value to my funtion which writes the value in json but I don't know how to
def signup_page(filename="accounts.json"):
top = Toplevel()
top.title("Sign up page")
top.geometry('700x600')
top.resizable(False,False)
signup_label = Label(...
-3votes
0answers
37views
How does a function without a return statement affect an object that is passed to it? [closed]
How is the list 's' affected by the function, which does not have a return statement?
def test(s):
s.reverse()
s = 'program'
s = list(s)
test(s)
print(s)
Output:
['m', 'a', 'r', 'g', 'o', 'r', '...
-2votes
1answer
20views
unction return values only working once in python
The code below runs and prints out the values returned from the two functions test_value(address) and checkRepeatCount(address) when i try to add the two value returned i None as the result. Anyway to ...
-1votes
3answers
73views
No idea on how to create a function that determines if a number has an even digit within
I am learning to create functions. The whole program basically prints only the even digits of a number, but I need to create a function that, in case the number has no even digits, will print that it ...
0votes
0answers
13views
What is this type of function call with 2 pairs of brackets `BatchNormalization(axis = 3)(X, training = training)` in Python?
I was going through some python code today, I saw some weird syntax of calling function with 2 sets of parameters BatchNormalization(axis = 3)(X, training = training)
Can any say what is it called in ...
0votes
1answer
28views
How can I invoke return True or retutrn False from a class function of an external file?
Can I call, thanks to self or something similar, return True or retutrn False from the function of a class of an external file?
I need this because the main file (Page1) needs to know if a result is ...
-1votes
3answers
62views
How to add elements of list of linked list in straight order?
How can I add elements of list of linked list in straight order?
For example, I have list of linked list: [[1, 2, 3], [4, 5, 6], [7, 8]] and list new_list and I wanna add all the elements in order 1-&...
0votes
1answer
24views
Python Function with multiple arugements, some known, some unknown
I've tried to search for the answer to this around the web, and I'm not sure if I'm phrasing it properly or not, but I can't seem to find my answer. What I'd like to do is write a function that does ...
0votes
1answer
18views
How to fix ValueError for piecewise function plot
I am currently working on the following python script to plot the given piecewise function over the specified domain np.linspace(1.0, 3.0) and have run into some plotting errors. When I run the script,...
-1votes
0answers
33views
How do I stop a dictionary containing a command from running automatically? [duplicate]
I have a simple dictionary :
commands = {
'input': input("Say \"Hello World!\" ")
}
I want to be able to call the dictionary item and save the user's input into a variable ...
0votes
0answers
11views
Python3: class member function call preceded by class member variable?
I'm trying to program a Montecarlo Tree Search implementation for a TicTacToe.
I'm using the code from this page as an example to test initially.
So basically I'm getting an error when program tries ...
-1votes
0answers
16views
Make a function with a string [duplicate]
I want to complete my project its about run the python scripts directly like this example:
script = input("Run the script : ") #get script user input
def run():
script #the script write ...
0votes
1answer
37views
Find and replace values in txt file with the data provided in another excel file
I have an excel file like this:
Excel
And another txt file like this:
.subckt blockA vdd vss A B C Out
xi01 vdd vss vdd vss x1 A inv cpp=64n m=1 ln=22n lp=22n nf_n=1 nf_p=1 nfin_n=4 nfin_p=4
xi02 vdd ...
0votes
0answers
24views
How to calculate change in coins in python
I was given a prompt that asks to input any amount of money and print how many of each coin is needed for that amount of money. For example, 2.05 would be 8 quarters and 1 nickel. I thought I had it ...
1vote
1answer
9views
I'm trying to make a function that returns the color of a fruit from dictionary with a try/exception code built within a for loop, but it don't work
'''
Fruits_by_color = {'Yellow':{'Banana', 'Pineapple', 'Passion_Fruit'}, 'Green':{'Avocado', 'Lime', 'Water_melon'}, 'Red':{'Strawberries', 'Apples', 'RaspBerries', 'Pomegranate'}}
def Fruit_color(...
0votes
0answers
21views
Python3 problem with recalling a function
i have a part of code presented below and my issue is when i try to call bet_definer(point, digit_option, bet_team, m, url)(i marked it below in code) nothing happens, but it's supposed to run ...
0votes
0answers
23views
Use element outside of a function. Error NameError: name 'xxx' is not defined [duplicate]
In a tkinter window I would like to recall, for example, departure derived from a function (departurr is derived, through a function, from a combobox), but I get the error NameError: name 'departure' ...
0votes
0answers
10views
How to pass function in terminal with file path as an argument
#I am typing this in terminal or in cmd -->
#python pract33.py main "C:\Users\Sharad\Desktop\New folder (2)\GSTR3B.pdf"
#I also know many methods like using "\" or "/" ...
0votes
1answer
48views
find and call any function by function in string
It is tricky question, I need to know one thing that...
two function with different functionality and one more function called 3rd function which will decide that to use any one function. That ...
0votes
0answers
63views
Call a function of a function (classless) and use it?
I would like to nest some functions, then call the functions of the function example. There are no classes. How can I call the Button1_func and Button2_func functions contained in the example function?...
0votes
1answer
24views
TypeError cannot unpack non-iterable float object in centered average algorithm Python
I have a Type Error from centered average algorithm in Python. this is my code
def calc_centered_average(numbers):
sorted_list = sorted(numbers)
return sum(sorted_list[1:-1])/(len(numbers)-2)
...
0votes
1answer
28views
How to call a variable within a function if it runs under a Class
How to call a variable within a function:
What is the Right approach:
Should define the variable before class or
We can define it under the class or function
Sample Code:
#!/usr/bin/env python3
# -*-...
0votes
0answers
6views
To ensure pandas and numpy are loaded for a user-defined function
I am writing a function in Python (version 3.6.10) that will be used by someone else.
The function requires numpy and pandas and I am using these libraries without aliasing them.
Assuming minimum ...
0votes
1answer
28views
What does it mean to use 'if not' before a function name in Python?
I have come across some code I can't work out and for which there is no provided explanation. I have tried! The code is in two parts and runs a computer health check. In the second block, what does ...
0votes
0answers
17views
Python List append issues [duplicate]
Can anyone explain what is happening here? When I append(l) to combs,
combs = [[4,1]] and l=[3,2], so the expected result should be [[4,1],[3,2]] but instead it is [[3,2],[3,2]].
Also, if the same ...
0votes
1answer
12views
create a function to remove or replace last numbers from a list containing 2 values per sublist
I have a long list containing a lot of sublists which exist of 2 "values",
for instance
test=[["AAAGG1","AAAAA22"],["GGGGA1","AAGGA"],["GGGGG23&...
1vote
1answer
20views
Python3 function that adds elements from master list together
So if master list is:
master_list = [“tom”, “bob”]
The new list should be:
new_list = [‘tomtom”, “tombob”, “bobbob”, “bobtom”]
-1votes
4answers
41views
Format message by calling a written python function name in string
I have functions
def getName():
name = "Mark"
return name
def getDay():
day = "Tuesday"
return day
I have a variable
message = "Hi there [getName] today is [...
1vote
2answers
42views
The sum function isn't universal. So which is?
I've recently used the sum() function on a list of characters. An error occurred:
TypeError: unsupported operand type(s) for +: 'int' and 'str'
I've started writing a function for replacement and ...
0votes
2answers
35views
Converting an integer to a sequence of letters using a function
I want to create a function that takes an integer (say 234) and returns it as letters (cde).
I have managed to form some code that takes the number and separates it into its numeric components
def ...
1vote
1answer
16views
Python text game, where does this None come from?
I'm trying to make a text based game, and, to make sure it fits in the screen and doesn't look too bad, I made this little function using the Fill method from Wrapper.
def reescalate_text(string):
...
0votes
1answer
26views
How can i use for loop in lambda or any one line function?
I have a task to transform this code to one line and I really dont know how to do it. I couldnt find anything that solve this problem.
Here's the code:
def rowsub(mat, row1, row2, factor):
for i in ...
0votes
1answer
15views
how I can call specefic function with list
I have this class for call functions from post class and run them
class getitem(post):
def item_list(self):
item=[self.X(),self.A(),self.D(),self.I(),self.S(),self.V()]
...
0votes
2answers
20views
Python variable manipulated indirectly without being mentioned in function
I'm a coding beginner that's putting a project together for a game. To update the game board, I use this function:
Board = [0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
def boardupdate(self, move):
...
0votes
2answers
21views
Python finally block not catching errors
Take a look at a chunk of code:
move = [None, 20, 5, True, "a"]
valnum = 0
for val in move:
try:
if val >= 15:
val -= 3
move[...