Python:如何获得1到10之间的输入?

时间:2017-11-30 20:21:22

标签: python list if-statement input output

while True:
    print ("wanna exit? type a number that not between(1-11)range")
    side1 = input("Type 1st side: ")
    side2 = input("Type 2st side: ")
    side3 = input("Type 3rd side: ")
    a= [1,11]
    if   (side1 not in a) :
            print("You exit,goodbye! ")
            break
    else:
            a = int(side1)
            b = int(side2)
            c= int(side3)
            perimeter = (a + b +c )
            print ("The perimeter of triangle is :", perimeter )

我输入1到10之间的数字,但它一次又一次地输出“你退出......”

1 个答案:

答案 0 :(得分:3)

input()返回一个字符串,而a只存储整数。其次,您需要创建一系列值,而不仅仅是[1, 11]列表。

side1 = int(input("Type 1st side: "))
side2 = int(input("Type 2st side: "))
side3 = int(input("Type 3rd side: "))
a= range(1, 12)