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
Here's an example of addition:
#addition
def add():
total= num1+num2
print(total)
#using the function
num1= int(input("Enter num1?: "))
num2= int(input("Enter num2?: "))
add()
oop stands for object oriented programming, its serves the purpose of encapsulation ,abstraction , inheritance and isomorphism .
classes are used in python to do this , a class instance can be initialized with some data then the methods of that class can use that data internally to do smthing (encapsulation) . i see making a class in itself as a way of abstraction . and these classes can be sub classes or parent classes of other classes so inheritance . i dont know much about polymorphism
I am doing both inside the function or outside?
Could you give me a prompt that would require me to do both?(addition and subtraction)
I always aim to solve the problem regardless of the route that I am taking.
That's why I asked, do they both (void-function and value-returning functions) lead to the same outcome?.
I was in a rush last night.
I had the exam this morning and I wanted to quickly understand.
I could write a void-function and a return valid function but I didn't know what actually made them different. Like are they interchangeable or not. So, I was limited on time to go deeper on it.
Otherwise, I would've taken my time with it.
I am finding it hard to do.
I will take it as a homework.
Thank you for working with me
res = add(2,3)
res1(res, 5)
if you find it hard to understand
I have.
With returns I don't need to use a global variable
What if you want to do something like add wto numbers then add another number to that result?
Читать полностью…
#Using a void fucntion with a variable
def add(x,y):
addition = x+y
print(addition)
add(3,3)
I did yes.
I normally would've done that but, I had a very little time
I thought your question was more complicated than it was.
I defined separate functions. One calculates savings and the other calculates revenue just to use the addition and subtraction.
I was struggling to find something they have in common where I'd need to use both addition and subtraction.
After some headache, I reread your question and it was not even that difficult 😂
They lead to an insight.
Define void functions add and subtract. Use them somewhere else.
If you have add and subtract void functions, you either do add or subtract, but can you do both? First one then the other?
Читать полностью…
Exactly where I wanted to get you to and exactly the reason why you should be trying things out.
Читать полностью…
#Using a void fucntion with a variable
def add(x,y):
global addition
addition = x+y
print(addition)
add(3,3)
"""of course I meant using
the void functions"""
b,a = 2,2
addition += b+a
print(addition)
#Using a return value function:
def add(x,y):
return x+y
total= add(3,3)
print(f"Charly, this your total: {total}")
"""What if you want to do something
like add wto numbers then add an
other number to that result?"""
a,b = 2,2
total += a+b
print(total)
@Carlangueitor
Now, to my beginner eyes, I get 6 each time.
So, I wonder what makes one different to the other in this case!
#Using a return value function:
def add(x,y):
return x+y
total= add(3,3)
print(f"Charly, this your total: {total}")
The difference is not about how many times you call it but returning something or not
Читать полностью…
I tried it last night.
The week before. I have written the same code over and over.
But, one is a void function, the other is a returning value function. But If I use a variable with the void function, I am getting the same results. So, I wondered what makes one different to the other?
Again, not to bo rude but incetivate you to be more proactive 👍
Читать полностью…