Issue
I use python 3 and am trying to figure out how to evaluate a user input string and check for certain characters.
I know that this title is probably going to make it sound like I haven't heard of the .isdecimal() method, but in fact I am trying to allow for a user to input some number as a decimal, including the period, and this is what seems to make the evaluation hard.
For instance,
dec = input()
dec.isdecimal()
Returns False if I have the input 0.5 I could convert the input to a decimal perhaps, but if I don't want to limit the user's input to whole numbers, I'm not sure how else I can approach this evaluation.
Solution
IIUC, you just want to check if your string has a decimal in it. In that case, you could simply do the following.
inp_string = input()
def check_decimal(inp_string):
return ('.' in inp_string)
check_decimal(inp_string)
Answered By - Sheldore Answer Checked By - Willingham (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.