sf_population, sf_area = 864816, 231.89
rio_population, rio_area = 6453682, 486.5
sf_area = (int(sf_area))
rio_area = (int(rio_area))
def x= sf_population/sf_area
def y= rio_population/rio_area
if x<y:
print"True"
if x>y:
print"False"
答案 0 :(得分:1)
工作示例:
sf_population, sf_area = 864816, 231.89
rio_population, rio_area = 6453682, 486.5
sf_area = int(sf_area)
rio_area = int(rio_area)
x = sf_population/sf_area
y = rio_population/rio_area
if x < y:
print"True"
if x > y:
print"False"
答案 1 :(得分:0)
def
来定义函数,而不是变量。要将x
的值设置为sf_population/sf_area
,只需将def
放在第5行和第6行。
答案 2 :(得分:0)
sf_population, sf_area = 864816, 231.89
rio_population, rio_area = 6453682, 486.5
sf_area = (int(sf_area))
rio_area = (int(rio_area))
x = sf_population/sf_area
y = rio_population/rio_area
if x<y:
print "True"
if x>y:
print "False"
除非你想定义一个函数,否则不需要def
除此之外,请考虑将elif
用于第二个条件
if x<y:
print "True"
elif x>y:
print "False"