我的代码一直在说AttributeError:'str'对象没有属性'formart'

时间:2018-09-14 01:42:37

标签: python

select customers.* from customers inner join my_table on customers.id = my_table.list_element_id

salary = float(input("What is your salary?"))
  if salary > 1250.00 :
     new = salary*0.1
    print("the increase was {}".formart(new))
if salary <= 1250.00:
    new = salary*0.15
    print("the increase was {}".formart(new))

1 个答案:

答案 0 :(得分:1)

这是一个简单的错字,formart应该是format,缩进也很糟糕:

salary = float(input("What is your salary?"))
if salary > 1250.00 :
    new = salary*0.1
    print("the increase was {}".format(new))
if salary <= 1250.00:
    new = salary*0.15
    print("the increase was {}".format(new))

您还可以使用'%'

salary = float(input("What is your salary?"))
if salary > 1250.00 :
    new = salary*0.1
    print("the increase was %s"%(new))
if salary <= 1250.00:
    new = salary*0.15
    print("the increase was %s"%(new))

如果版本> pytho 3.6,则为f字符串:

salary = float(input("What is your salary?"))
if salary > 1250.00 :
    new = salary*0.1
    print(f"the increase was {new}")
if salary <= 1250.00:
    new = salary*0.15
    print(f"the increase was {new}")

或者在这种情况下最好的方法:

salary = float(input("What is your salary?"))
if salary > 1250.00 :
    new = salary*0.1
    print("the increase was", new)
if salary <= 1250.00:
    new = salary*0.15
    print("the increase was", new)