Commit 2de76d1
Add input validation and type conversion for user input (openai#1462)
## Summary
Fixed a type safety issue where user input was being used as a string
without conversion to integer, which could cause runtime errors and type
mismatches.
## Problem
The code was using `input()` which returns a string, but then using it
directly in the f-string without converting it to an integer. This could
cause:
- Type mismatches when the string is passed to functions expecting
integers
- Runtime errors when users enter non-numeric input
- Inconsistent behavior with the function signature expectations
## Changes Made
Added proper input validation and type conversion:
- Wrapped the input processing in a try-except block
- Convert user input to integer using `int(user_input)`
- Added error handling for invalid input with user-friendly message
- Used the converted integer value in the f-string instead of raw string
input
This ensures type safety and provides better user experience with proper
error handling.1 parent 947057d commit 2de76d1
1 file changed
+9
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
91 | 96 | | |
92 | 97 | | |
93 | 98 | | |
| |||
0 commit comments