135201
You will be muted until you read the rules. Read them! @Rules_for_Python A group about the Python programming language. Offtopic things go here: @pythonofftopic Resources to learn python: @pythonres Group for Hy: @hylang Selenium: @SeleniumPython
Yes. You cannot get output of a void function without using globals. By using using globals you make the code complicated. After calling the void function, you need to know the name of the global variable to access the result. You need to assign it to other variables if you reuse the void function. With functions that return values, everything appears to be cleaner and reusable.
Читать полностью…
I am already in a rabbit hole trying to learn what prompt is python 😂
Читать полностью…
def add(x, y):Читать полностью…
global result_add
result_add = x + y
def get_input(prompt):
global result_input
result_input = int(input(prompt))
get_input("x")
x = result_input
get_input("y")
y = result_input
add(x, y)
print(result_add)
Why do I get the feeling that I am sent to do something undoable🙂
Читать полностью…
When I use the functions twice, do you want me to add the result of the previous to the second or you want two independent results from the same function?
Читать полностью…
More like
def user_input_void():Читать полностью…
global x
x = int(input("Enter x: "))
Let me tag them for you.
I have already sent it in this group
And what you did not know yet is that global variables pollute the global scope. You can assign values to it as well, not only read from them. It can get very confusing quickly.
Читать полностью…
12 lines of complicated code vs just 8 lines of clear code
Читать полностью…
How does it compare to this one?
def add(x, y):Читать полностью…
return x + y
def get_input(prompt):
return int(input(f"Enter value for {prompt}: "))
x = get_input("x")
y = get_input("y")
result = add(x, y)
print(result)
It's just a variable.
I had to make a problem to solve or else they'd be no end point.
#monthly income
def income():
remaining_balance = int(input("Enter the remain: "))
expenses = int(input("Enter the expenses: "))
global total
total = remaining_balance + expenses
income()
print(f"your total income is: {total}")
#extended...
total = income()
print(total)
The purpose is not to torture you but to make a point. We can go from what you have so far.
Читать полностью…
I wouldn't say I am stuck but I am not making that much progress 😂
Читать полностью…
Let's make a deal. You do the versions with void function, where the user_input_void function is used twice to get the input from the user, and I do the one with the return statements. But also add the two inputs from the user with add_void.
#void-func extended:
def add_void(x,y):
global result
result = x+y
print(result)
add_void(3,3)
add_void(result, 4)
void_input = int(input("Enter your number?: "))
add_void(result,void_input)
Output: 10+input