Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
assert
#2
This is not valid verification of the number type:
gender is int() or float()
And the hidden problem is that you get your variables as a strings (with the input() function). So the similar valid verification wouldn't succeed anyway.

You can write down and use some function for a number like strings validation:
def is_string_number(string: str) -> bool:
    # It validates integers as well as floats
    try:
        # It tries to cast the string to the float
        float(string)
        # It it succeed it returns True
        return True
    except ValueError:
        # If it failed it returns False
        return False
Reply


Messages In This Thread
assert - by Naito - Jan-16-2019, 10:52 AM
RE: assert - by ODIS - Jan-16-2019, 05:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Assert failure jtcostel 1 1,616 Sep-03-2021, 05:28 PM
Last Post: buran
  Assert that dictionary contains a key phpMick 3 38,092 Nov-27-2019, 11:36 AM
Last Post: buran

Forum Jump:

User Panel Messages

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