ValueError: invalid literal for int () with base 10

前端 未结 3 614
孤城傲影
孤城傲影 2020-11-28 05:29

I wrote a program to solve y = a^x and then project it on a graph. The problem is that whenever a < 1 I get the error:

V

3条回答
  •  误落风尘
    2020-11-28 06:31

    It might be better to validate a right when it is input.

    try:
      a = int(input("Enter 'a' "))
    except ValueError:
      print('PLease input a valid integer')
    

    This either casts a to an int so you can be assured that it is an integer for all later uses or it handles the exception and alerts the user

提交回复
热议问题