初学者在这里使用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()
答案 0 :(得分:0)
你计算了这个值并打印出来,但是后来你没有使用它。此修复程序将使其工作:)
class Overpriced(Property):
def testprice(self):
computed_price = int(information['cap']) / (12 * int(information['rent']))
print "The price to rental ratio for the property =",computed_price
if computed_price > 40:
print "This is an expensive property."
elif (computed_price > 25) and (computed_price < 40):
print "This property is a bit expensive."
else:
print "Testing."
tprice = Overpriced()
tprice.testprice()