Write a program that will keep asking for a user input (until a blank line is entered) and will inform me whether what I entered was a valid number or not (without crashing). The program should use at least one try/except loop The program should include at least two custom written functions (a main() function can count as one of the two)

Respuesta :

Answer:

Follows are the program code to this question:

def check():#defining a method check

   while(True):#defining a while loop that uses for the input value

       x=input("Enter value to check valid or not: ")#print message

       if x=='':#use if block that check input is null  

           break#use break keyword for exit

       else:#defining else block

           try:#use try block

               x=float(x)#use x vaiable to convert value into float

               print("valid number")#print message

           except:#use except block

               print("not valid number")#print message

           continue#use continue keyword

check()#call ing method

Output:

please find the attachment.

Explanation:

In the above-given program, a method "check" is defined, and inside the method, a while loop is used to input the value in the "x" variable.

In the next step, a conditional statement is used in the if block, it checks if x value is equal to null it will use break keyword to exit the program.

In the else block x variable is used, that converts the integer value into float and uses the try and except for check the given value and print the message respectively.

Ver imagen codiepienagoya