d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Quick Easy Question > Python
Add Reply New Topic New Poll
Member
Posts: 2,957
Joined: Aug 29 2011
Gold: 0.00
Apr 23 2018 09:59pm
def initialize(y):
x = 0.0
x = y
output(x)
output(y)

def output(x):
print(x)

def main():
x = 0.0
y = 2.0

output(x)
output(y)
initialize(y)
output(x)
output(y)

why won't this code work and what is the output if it were to work?
thanks!
25fg for whoever answers this in the next 15 mins
Member
Posts: 23,728
Joined: Aug 21 2007
Gold: 433.48
Trader: Trusted
Apr 24 2018 07:15am
not a python pro but I guess it doesnt work because the function output is not defined when you call it at initialize. So reorder it:

Code


def output(x):
print(x)

def initialize(y):
x = 0.0
x = y
output(x)
output(y)


def main():
x = 0.0
y = 2.0

output(x)
output(y)
initialize(y)
output(x)
output(y)

Go Back To Programming & Development Topic List
Add Reply New Topic New Poll