如何修复错误信息?

时间:2017-11-09 15:12:59

标签: python

这是第一次使用python编写程序,我试图只允许用户输入8位数。我设法做到这一点,每次我输入多于或少于8时,它会给出错误消息,但是如果我输入8位数,它仍然会给出错误消息

    value3 = input("please enter your card number: ")
while not value3.isdigit():
    value3= input("please enter your card NUMBER: ")
if len(value3) > 8:
    while True:
        value3 = input("Error! Only 8 characters allowed!: ")
if len(value3) < 8:
    while True:
        value3 = input("Error! Only 8 characters allowed!: ")

2 个答案:

答案 0 :(得分:2)

您不应在value3 = input("please enter your card number: ") while True: if not value3.isdigit(): value3= input("please enter your card NUMBER, Only digits are allowed: ") continue elif len(value3) != 8: value3 = input("Error! Only 8 digits allowed!: ") else: print("Valid card number") break 语句中使用wildfly: build: dockerfile: Dockerfile.wildfly context: . volumes_from: - logvolume depends_on: - logvolume - mariadb-wildfly mariadb-wildfly: extends: file: common-services.yml service: mariadb-common # ports: # - "3307:3307" # ------------------------------------------------------------------------ firefly: build: dockerfile: Dockerfile.wildfly context: . volumes_from: - logvolume depends_on: - logvolume - mariadb-firefly mariadb-firefly: extends: file: common-services.yml service: mariadb-common

您可以这样做:

wildfly-moskito:
    extends:
        file: common-services.yml
        service: wildfly-common

答案 1 :(得分:1)

看来你在while循环中有“错误消息”,条件总是设置为true。所以无论你输入什么,你的程序仍然停留在while循环中。 更好的方法可能是定义一个“错误函数”,当输入大于/小于8时,它会被调用。