【问题标题】:I keep getting an error on Python, TypeError: unsupported operand type(s) for /: 'tuple' and 'int' What am I doing wrong?我在 Python 上不断收到错误,TypeError: unsupported operand type(s) for /: 'tuple' and 'int' 我做错了什么?
【发布时间】:2021-10-10 02:11:27
【问题描述】:

复利计算器

#输入

P = (float, input("Enter the starting principal: ") )
R = (float, input("Enter the annual interest rate: ") )
m = (int, input("How many times per year is the interest compounded? ") )
t = (float, input("For how many years will the account earn interest? ") )

#计算

#FV = P * ( 1 + ( (R/100) / m ) ) ** ( m * t)

FV = P * ( 1 + ( (R/100) / m ) ) ** ( m * t)

#输出

print("At the end of ", t, "years. You will have $", format(FV, ",.2f") ) 

【问题讨论】:

    标签: python compiler-errors


    【解决方案1】:

    正确的语法:

    input_variable = float(input("some text"))
    input_variable= int(input("some text"))
    

    【讨论】:

    • 哇,我觉得自己很笨,谢谢你,哈哈!天哪,我已经尝试修复它几个小时了,多么简单的修复,非常感谢我不擅长编程仍在努力学习!
    【解决方案2】:
    P = float(input("Enter the starting principal: ") )
    R = float(input("Enter the annual interest rate: ") )
    m = int(input("How many times per year is the interest compounded? ") ) )
    t = float(input("For how many years will the account earn interest? ") )
    
    FV = P * ( 1 + ( (R/100) / m ) ) ** ( m * t)
    
    print("At the end of ", t, "years. You will have $", format(FV, ",.2f") )
    

    float, input("bla bla bla")) 应该类似于 float(input("bla bla bla"))) 并使用 int, input("bla bla bla")) 将其更改为:int(input("bla bla bla"))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-27
      • 2020-04-14
      • 2016-08-30
      • 1970-01-01
      • 2021-12-25
      • 2020-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多