print("this program will calculate the area")
input("[Press any key to start]")
width = int(input("enter width"))
if width < 0:
print ("please chose a number between 0-1000")
width = int(input("enter width"))
if width > 1000000:
print ("please chose a number between 0-1000")
width = int(input("enter width"))
height = int(input("Enter Height"))
area = width*height
print("The area is:",area)
有没有一种方法可以压缩下面的代码,例如将它们放在一起,这样我就不必编写除了less then和greater then语句两次以外的同一行代码。Python if语句
width = int(input("enter width"))
if width < 0:
print ("please chose a number between 0-1000")
width = int(input("enter width"))
if width > 1000000:
print ("please chose a number between 0-1000")
width = int(input("enter width"))
我已经试过
width = int(input("enter width"))
if width < 0 and > 10000:
print ("please chose a number between 0-1000")
width = int(input("enter width"))
但我得到没有爱。
我也不想键入
width = int(input("enter width"))
声明两次,如果它能够得到帮助。
感谢 本
不错的工作家伙,Ty为您的时间。 – BenniMcBeno 2013-03-08 00:10:28