Начинает с python здесь.Программа Python производит неправильный вывод
Просто написал простую программу, но результат неверен. Я должен упустить что-то очень основное.
Пример входных данных:
Prody
1000000
3000
Выход:
Hi Prody
The property price is: 1000000
The estimated rental cost for the property is: 3000
The price to rental ratio for the property = 27
This is an expensive property.
Но выход должен быть:
Hi Prody
The property price is: 1000000
The estimated rental cost for the property is: 3000
The price to rental ratio for the property = 27
This property is a bit expensive.
Что случилось?
Спасибо!
Код:
information = {'name': '0', 'cap': 0, 'rent': 0}
print "First you need to provide some information."
information['name'] = raw_input("What is your name?")
information['cap'] = raw_input("What is the cost of the property?")
information['rent'] = raw_input("What is the estimated rent for the property?")
print "\n"
print "Hi", information['name']
print "The property price is: ", information['cap']
print "The estimated rental cost for the property is: ", information['rent']
print "\n"
class Property(object):
def enter(self):
pass
class Overpriced(Property):
def testprice(self):
print "The price to rental ratio for the property =",
int(information['cap'])/(12 * int(information['rent']))
if tprice > 40:
print "This is an expensive property."
elif (tprice > 25) and (tprice < 40):
print "This property is a bit expensive."
else:
print "Testing."
tprice = Overpriced()
tprice.testprice()
Спасибо за комментарии, изменил последнюю часть к:
class Overpriced(Property):
def testprice(self):
rental_ratio = int(information['cap'])/(12 * int(information['rent']))
print "The price to rental ratio for the property =", rental_ratio
if rental_ratio > 40:
print "This is an expensive property."
elif (rental_ratio > 25) and (rental_ratio < 40):
print "This property is a bit expensive."
else:
print "Testing."
tprice = Overpriced()
tprice.testprice()
Вы понимаете, какое значение имеет значение 'tprice'? 'tprice' - это объект, который присваивается' Overpriced() '. Используйте разные переменные. –
Как вы можете сравнить «экземпляр класса» с значением? –
спасибо за обзор первоначального сообщения @sammy – Prody