Hello from a super noob!

MRAB python at mrabarnett.plus.com
Wed Jun 7 20:34:56 EDT 2017


On 2017-06-08 00:56, CB wrote:
> 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
>                
> 
You haven't said what the problem is.

It looks OK, apart from the indentation, which is important to get right 
in Python.

Also, you've defined a function 'main' but not called it, and imported a 
module but not used it, which is pointless.



More information about the Python-list mailing list