File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change 1+ # ...existing code... 
12#!/usr/bin/env python3 
23
34# Created by: Angelo Garcia 
67
78
89def  main ():
9-     # This function uses a try statement to catch  input errors  
10+     # This function demonstrates validating user  input with try/except/finally  
1011
11-     # input 
12+     # input - prompt the user for the number of students (input returns a string)  
1213    integer_as_string  =  input ("Enter the number of students: " )
1314    print ("" )
1415
1516    # Process & output 
1617    try :
18+         # Try to convert the input string to an integer 
1719        integer_as_number  =  int (integer_as_string )
18-         print ("you  entered an integer correctly!" )
20+         print ("You  entered an integer correctly!" )
1921    except  Exception :
22+         # If conversion fails, inform the user the input was not an integer 
2023        print ("That was not an integer!" )
2124    finally :
25+         # This always runs whether conversion succeeded or failed 
2226        print ("Thank you for playing." )
2327
2428
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments