File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change 1- # ...existing code... 
21#!/usr/bin/env python3 
32
43# Created by: Angelo Garcia 
54# Created on: September 30th, 2025 
6- # This program  uses a  try statement  to catch input errors  
5+ # Program  uses try/except/finally  to check integer input  
76
87
98def  main ():
10-     # This  function demonstrates validating user  input with try/except/finally  
9+     # main  function: run the  input check  
1110
12-     # input -  prompt the  user for the  number of students (input returns a string ) 
11+     # prompt user for number of students (stores text ) 
1312    integer_as_string  =  input ("Enter the number of students: " )
13+     # print a blank line to separate input from output 
1414    print ("" )
1515
16-     # Process & output 
1716    try :
18-         # Try to  convert the  input string  to an integer 
17+         # convert input text  to an integer 
1918        integer_as_number  =  int (integer_as_string )
19+         # notify user the input was a valid integer 
2020        print ("You entered an integer correctly!" )
2121    except  Exception :
22-         # If conversion fails, inform the  user the input was not an integer 
22+         # notify  user the input was not an integer 
2323        print ("That was not an integer!" )
2424    finally :
25-         # This  always runs whether conversion succeeded or failed  
25+         # always print a closing message  
2626        print ("Thank you for playing." )
2727
2828
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments