Пустой ввод в Python - PullRequest
       8

Пустой ввод в Python

0 голосов
/ 08 сентября 2018

Я только что узнал о циклах while и написал этот код для этого проекта, который проходит все квалификации, кроме одной. Первый - когда пользователь нажимает ввод (ничего не вводит), он должен продолжать спрашивать. У меня проблемы с установлением этого в программе. Код ниже:

def str_analysis(question):
    while True:   
        if question.isdigit() == True:
            if int(question) > 99:
                print (question,"is a big number!")
                break
            else:
                print (question,"is a small number!")
                break     
        if question.isalpha() == True:
            print (question,"is all alphabetical characters!")
            break
        else:
            print (question, "is neither all alpha nor all digit.")
            break


str_analysis(question = input("Enter word or integer: "))

Я пытался поставить это под

while True:
if question == "":
print ("") 

в надежде, что он продолжит спрашивать но когда я делаю это, он просто переходит к (вопрос: «не все ли буквы, ни все цифры»)

1 Ответ

0 голосов
/ 08 сентября 2018

Это можно немного убрать, но просто исправьте вашу проблему.

def str_analysis(question):
    while True:

        if question.isdigit() == True:

            if int(question) > 99:
                print (question,"is a big number!")
                break

            else:
                print (question,"is a small number!")
                break


        elif question.isalpha() == True:
            print (question,"is all alphabetical characters!")
            break

        else:

            print (question, "is neither all alpha nor all digit.")
            question = input("Enter word or integer: ")





str_analysis(question = input("Enter word or integer: "))
...