Hi everyone,
I am taking a python class and I'm stuck in an exercise.

what am i doing wrong? Can anyone try to run it? Thanks so much! 

#Description:Input validation and while loops.


import random
def main(): #main function need in all programs for automated testing
    

    #your program goes here
    
    print()



    
    print("This program will help us practice input validation and while 
loops.")
    print("The user will be asked to enter two numbers which will both be 
validated. ")
    print("The sum of the numbers will then be displayed in a complex print 
statement ")
    print("and the user will be asked if they would like to run the program 
again."
)
    print()
    print()
    
    while True:    
        FirstNumber = input ("Please enter the first number: ")
        if FirstNumber.isdigit ():
            FirstNumber = int(FirstNumber)
                break 
        else:
          print ("Invalid response. Please enter a whole number. " )
                
        while True:
                        
            SecondNumber = input ("Please enter the second number: " )
            if SecondNumber.isdigit():
                SecondNumber= int(SecondNumber)

                    break
            else:
                print("Invalid response. Please enter a whole number." )
                            
        print()
        print (str(FirstNumber) + " + " + str(SecondNumber)+ " = " + 
str(FirstNumber + SecondNumber))
        print()
                    
        while True:
                        
            ans= input('Would you like to run the program again (Y/N) : ')
            if ans== 'Y' or ans== 'N':
                    break

            else:
                print(" lnvalid response. Please answer with 'Y' or 'N' ")

        if ans== 'N':
                    break            
              

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to