0

I have this code:

import sys

x=0
y=0
z=0

def Total(a,b,c):
  a=1
  b=2
  c=a+b
  return c

Total(x,y,z)
print(z)

I initially anticipated a result of 3, but unfortunately, the outcome is still 0. How can I resolve this issue?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Bigboi
  • 13
  • 2

2 Answers2

0

You need to assign the returned value of Total to z. Right now you aren't doing anything with the returned value of Total(x,y,z).

x=0
y=0
z=0

def Total(a,b,c):
    a=1
    b=2
    c=a+b
    return c

Total(x,y,z) # Total returns 3, but the value is not assigned to anything
print(z) # Z is still 0

What you need is:

x=0
y=0
z=0

def Total(a,b,c):
    a=1
    b=2
    c=a+b
    return c

z = Total(x,y,z) # Assign the returned value of Total (which is 3) to z
print(z) # Print z (which is 3) out
tjfuller
  • 186
  • 1
  • 3
-1

try this it gives me 3 because the a and b have been set to x and y the doesnt need to be there

import sys
x=0
y=0
z=0
def Total(a,b):
  a=1
  b=2
  c=a+b
  print(c)
Total(x,y)

also why u usin sys

Apex862-2
  • 1
  • 2
  • Thank you for your suggestion. I did it. I am new to Python, so I just copied exactly the tutorial on the Internet without making sense of the reason for importing this library. Could you tell me why I shouldn't use it? – Bigboi Aug 02 '23 at 15:42
  • you can use it its just un neccesary if you dont do any thing with it its realitively harmless but it just makes me uncomfy and increases the file size by a smidge its still o to leave it if your going to use it – Apex862-2 Aug 15 '23 at 18:14