Python Forum
how to make sure an input is from the wanted type
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to make sure an input is from the wanted type
#2
>>> "2.2".isnumeric()
False
>>> "22".isnumeric()
True
>>> "022".isnumeric()
True
>>> int('000022')
22
Also you can just try/except the user input:
try:
    user_input = int(input("please guess a number between 0 and 10: \n"))
except ValueError:
    print('Not an integer! Please try again!')
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
RE: how to make sure an input is from the wanted type - by wavic - Oct-26-2022, 06:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to make it so whatever I input into a script gets outputted on a different file spermatozwario 4 1,329 Nov-24-2024, 12:58 PM
Last Post: deanhystad
  How to make input come after input if certain line inserted and if not runs OtherCode Adrian_L 6 4,899 Apr-04-2021, 06:10 PM
Last Post: Adrian_L
  Make the answer of input int and str enderfran2006 2 2,865 Oct-12-2020, 09:44 AM
Last Post: DeaD_EyE
  How to make input goto a different line mxl671 2 3,425 Feb-04-2020, 07:12 PM
Last Post: Marbelous
  Type hinting - return type based on parameter micseydel 2 3,274 Jan-14-2020, 01:20 AM
Last Post: micseydel
  how can i handle "expected a character " type error , when I input no character vivekagrey 2 3,732 Jan-05-2020, 11:50 AM
Last Post: vivekagrey
  catch input type error mcmxl22 5 4,353 Aug-11-2019, 07:33 AM
Last Post: wavic
  Getting type from input() function in Python 3.0 leodavinci1990 7 5,325 Jul-29-2019, 08:28 PM
Last Post: avorane
  how i can check the input type? Firdaos 3 3,773 Dec-13-2018, 11:39 PM
Last Post: wavic
  How to make an input trigger the output once no matter how long input is high cam2363 3 4,161 Feb-05-2018, 01:19 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020