Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to get rid of the decimal point in Python?
How to get rid of the decimal point in Python?
I used an if statement to judge whether the last two digits of s are .0, thus judging whether it is an integer. If it is an integer, I use int to convert it into an integer when I output it. If it is not, it is a floating-point number, and I will output it as it is, and I cannot force it to be an integer.

# code =gbk

D = float (input ("Please enter the bottom of the triangle:"))

H = float (input ("Please enter the height of triangle:"))

s = d * h / 2

If string [-2:] == ".0 ":

Print ("The area of triangle is:", int(s))

Otherwise:

Print ("The area of the triangle is:", s)

Here are two results: