Function that has if statement produces nothing when it's called [closed] - python

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
#4 gender differences
def d_gender(employee1, employee2):
if employee1.gender >= employee2.gender :
1
else :
0
d_gender(E1,E2)
Although everything is defined the function doesn't produce anything. What is wrong here?

You need a return statement in your function:
def d_gender(teacher, studio):
if teacher.gender >= studio.gender :
return 1
else :
return 0
Then you can decide what to do with the returned value. Maybe print:
print(d_gender(T1,S1))

Related

why does the return function in python is returning a value of 1 in factorial prog [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 months ago.
Improve this question
#factorial prog
def fac(y):
fact=1
i=1
for i in range(1,y+1):
fact=i*fact
return fact
x=int(input("enter no"))
y=fac(x)
print(y)
why does the return function return 1
when I remove the defined function and find the factorial by same method in the main function its giving the correct answer and even in the defined function when i print fact value is providing the correct ans but only the return function is not working
can someone give me the same method code instead of recursive function
Indentation level of your return statement is wrong. You should do as following:
#factorial prog
def fac(y):
fact=1
i=1
for i in range(1,y+1):
fact=i*fact
return fact

No output when executing a method/function in Python [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 months ago.
Improve this question
There is no output on command line. Also the variable input cannot be set.
I've tried removing the variable from class, same result.
class test:
input = ""
def __init__(this, input):
this.input = input
def output(this):
print(this.input)
obj = test("hallo")
obj.output
I expect the output to be hallo.
You need to call the method, not just refer to it:
obj.output()

Classes with vector inside [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
class Gate():
def _init_(self):
self.Code=""
self.Occupancy=False
self.AircraftID=" "
class BoardingArea():
def _init_(self):
self.Name=""
self.Schengen=False
self.Gate=[]
So I have this 2 classes, boarding area has a vector with numerous gates, when I try to fill that vector inside the class I get an error I tried various things but none seem to work, any ideas?
n=10
B=BoardingArea()
while n>0:
G=Gate()
code=elementos[1] + str(n)
G.Code=code
B.Gate.append(G)
n-=1
print B.__dict__
B.Gate.append(G)
AttributeError: BoardingArea instance has no attribute 'Gate'
Change _init_ to __init__ (double underscore)

TypeError: 'NoneType' object is not callable in factory function [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
#!/usr/bin/python
def maker(n):
def action(x):
return x*n
return action
f=maker(2)
print f(3)
I have problem here with type error.How to solve this two arguments problem,one is fixed.
You need to put the return action out of action function :
def maker(n):
def action(x):
return x*n
return action
f=maker(2)
print f(3)
Result:
6
Note that in factory function you must return the inner function as the result of main function.

Python app cannot print result [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have installed python on windows and i have written a function but this function just won't print a thing on the screen
def rock(x,y):
result = x * y
return result
print(rock(440,400))
What is the reason why this script isn't printing the result?.
This is because the print function is inside the function definition. Do this instead:
def rock(x,y):
result = x * y
return result
print(rock(440,400))

Categories

Resources