【发布时间】:2014-04-19 13:49:58
【问题描述】:
所以我有一个应该给出形状区域的简短程序。
当我调用 which_area(x) 时,它工作正常。但是当我把raw_input() 作为参数时(并且因为我把print choose_area 放在底部),shell 在输入后回复None。
我不太确定出了什么问题,但我认为这与return 声明以及我的表述方式有关。
感谢您提供任何帮助 :) 请感谢您。
从一个初级程序员开始。
def triangle_area():
print "What is the base length?"
base = raw_input()
print "What is the height?"
height = raw_input()
area = 0.5*float(base)*float(height)
print "The area of you triangle is:", area
def circle_area():
print "What is the radius of the circle?"
radius = raw_input()
area = 3.14159*(float(radius)**2)
print "The area of your circle is:", area
def square_area():
print "What is the length of the side of the square?"
print "(Remember that squares have equal sides, and if"
print "you want to enter a seperate length and width"
print "you have a rectangle.)"
length = raw_input()
area = float(length)**2
print "The area of your square is", area
def which_area(x):
if x == 1:
return triangle_area()
elif x == 2:
return circle_area()
elif x == 3:
return square_area()
else:
return "You didn't pick 1, 2, or 3."
def choose_area():
print "Calculate the area of which shape?"
print "1. a triangle"
print "2. a circle"
print "3. a square"
print "Enter a number to choose:"
which_area(raw_input())
print choose_area()
【问题讨论】:
-
选择 = raw_input; which_area(选择)
-
你的区域函数没有返回结果