【问题标题】:Python casting error: Invalid literal for int() with base 10Python 转换错误:int() 的文字无效,基数为 10
【发布时间】:2019-01-02 23:33:13
【问题描述】:

这是我的代码:

def arearectangle(length, breadth):
        totalarea = length * breadth
        return totalarea


def areasqr(side):
    ''' Objective : To compute the area of circle
   Input parameters : Length and Breadth
   Return Value : area - numeric Value
    :rtype: int'''
    area = side*side
    return area


def addition(num1, num2):
    '''The objective of this proram is to find the sum of two integers
     input through keyboard'''
    total = num1 + num2
    return total


def main ():
    print ("enter the length and breadth to find the area of rectangle")
    l1 = input(int('enter the length:'))
    l2 = input(int('enter the breadth'))
    rectarea = arearectangle(l1, l2)
    print("area of the rectangle is", rectarea)
    print("enter the following values to obtain the area of square")
    s1 = int(input('first side of square : intiger value :'))
    areas = areasqr(s1)
    print("Area of Square is ", areas)
    print("enter the following value to find out the sum")
    i = int(input('enter the first intiger : '))
    j = int(input('enter the seoond intiger : '))
    newtotal = addition(i, j)
    print('the sum of the entered intger is ', newtotal)


if __name__ == '__main__':
    main()

它会抛出以下错误:

  File "", line 22, in main
    l1 = input(int('enter the length:'))
ValueError: invalid literal for int() with base 10: 'enter the length:'

【问题讨论】:

  • 什么错误....?
  • 什么错误?请清楚地描述问题。阅读How to Ask 页面。
  • 你看过你自己的问题了吗?如果是这样,你真的认为这是可以接受的吗?
  • 进展如何?我的回答有用吗? :)

标签: python string casting


【解决方案1】:

你在错误的地方做演员。

移除 int() 演员表,将其带到 input() 之外

l1 = int(input('enter the length:'))
l2 = int(input('enter the breadth'))

这样就解决了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-10
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多