No output when executing a method/function in Python [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 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()

Related

TypeError: int object is not callable [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 1 year ago.
Improve this question
I am using python, and I have been facing this error for a week.
<module>
my_car.odometer_reading ()
TypeError: 'int' object is not callable
What is the solution please?
class Car:
def __init__(self,made,module,year):
self.made=made
self.module=module
self.year=year
self.odometer_reading=0
def update_odometer(self,mileage):
self.odometer_reading = mileage
my_car=Car('audio','q5','2021')
my_car.update_odometer(23)
my_car.odometer_reading ()
I tried a lot but without any result.
odometer_reading is not a function, its an int, so just print it
print(my_car.odometer_reading)

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)

Function that has if statement produces nothing when it's called [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 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))

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