Convert any user input to int in Python

后端 未结 3 420
别跟我提以往
别跟我提以往 2021-01-29 06:12

I need to convert user input to int. Below is what I have written so far which is not working out. It only accepts int. the end goal is to

3条回答
  •  醉话见心
    2021-01-29 07:03

    Apart from the other answers, you can use round() function:

    i = input("Enter any value: ")
    print(round(i))
    

    But if you want to simply cut the decimal part, you can use math lib and floor():

    import math
    i = input("Enter any value: ")
    print(math.floor(i))
    

提交回复
热议问题