Is there anyone who can give me some tips on Python?

Asked 2 years ago, Updated 2 years ago, 41 views

The isdigit() method function of the string verifies that it is a string consisting only of numbers. However, in order for the input string to be an integer string, one of the following two conditions must be satisfied.

The isinteger function, which takes an integer string s (including negative numbers) as an argument and gives True if it fits the integer format, or False otherwise, can be written as follows.

def isinteger(s):
    return s.isdigit() or s[0] == '-' and s[1:].isdigit()

For a string to be a fixed decimal point, one of the following conditions must be satisfied:

Let's write an isfloat function that takes the fixed-point string s as an argument and gives True if it fits the fixed-point format, or False otherwise.

Hint 2: First <String>.Use partitions ('.') to carve strings.

Function Call Execution Results

isfloat(".112") True

isfloat("-.112")    True

isfloat("3.14") True
isfloat("-3.14")    True

isfloat("5.")   True

isfloat("5.0")  True

isfloat("-777.0")   True

isfloat("-777.")    True

isfloat(".")    False

isfloat("..")   False

I don't know what you're talking about (Crying)

python isdigit partition

2022-09-22 16:15

1 Answers

def decimal (string):
    Integer part, decimal part = string.split('.')
    # Determine if the integer part is an integer or an integer function
    # Determine if the decimal part is an integer or an integer
    ...

I think it's a question to make sure that the string given in this way is a decimal representation.


2022-09-22 16:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.