Max
Max

Reputation: 39

How do I turn a .0 float into an integer in python?

I'm working on making a simple calculator to practice Tkinter in Python 3 and I want to be able to turn the output of an exponent equation like 2 to the 3rd from 8.0 to just 8 for aesthetic purposes. I tried using the strip function, but I'm a little confused.

import math
from tkinter import *

elif operation == "exponent":

    answer = str(math.pow(float(firstNum), 
    float(secondNum)))
    print(answer.strip("0"))
    print(answer.strip("."))

Upvotes: -2

Views: 1261

Answers (1)

Buddy Bob
Buddy Bob

Reputation: 5889

You don't need all of that. Say we had a float like 5.0, we can use int to turn it into 5.

int(5.0)

output

5

Upvotes: 1

Related Questions