0
User input
I am creating a python application to prompt user to enter either their zip code or city. How can I create input with options either it will be zip code which would be integer int(input()) and for city would be str(input()). But how to give option to enter either or.
3 Respuestas
+ 1
When it comes to this, you have 2 options:
1. Make the user choose
2. Make your program recognize wheter the input is a number or a string
I would suggest you the second one, as the first would need additional input management. Here's my example:
https://code.sololearn.com/cNAs9BhSRUz1/?ref=app
+ 1
Both city name and zip code input can be read in string format. So there probably be no need to convert input string to integer.
But the zip code format matters in this case. If a zip code consists of only digits then you can simply use <input_string>.isdigit() to verify all characters in <input_string> represent digits. It is unlikely (or rarely) for a city name to consists of digits only.
0
Thank you for great examples.