程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了这个 python 打印语句的最后一行中我连接的错误是什么?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决这个 python 打印语句的最后一行中我连接的错误是什么??

开发过程中遇到这个 python 打印语句的最后一行中我连接的错误是什么?的问题如何解决?下面主要结合日常开发的经验,给出你关于这个 python 打印语句的最后一行中我连接的错误是什么?的解决方法建议,希望对你解决这个 python 打印语句的最后一行中我连接的错误是什么?有所启发或帮助;

我在最后一行找不到错误。我是这门语言的完全初学者。提前致谢。

ingredIEnt_one = input("What is the first ingredIEnt?: ")
ing_one_oz = int(input("How many ounces of this ingredIEnt?: "))

ingredIEnt_two = input("What is the second ingredIEnt?: ")
ing_two_oz = int(input("How many ounces of this ingredIEnt?: "))

ingredIEnt_three = input("What is the third ingredIEnt?: ")
ing_three_oz = int(input("How many ounces of this ingredIEnt?: "))

servings_amt = int(input("How many servings would you like?: "))

ing_one_oz = ing_one_oz * servings_amt
ing_two_oz = ing_two_oz * servings_amt
ing_three_oz = ing_three_oz * servings_amt

print("In order to make " + str(servings_amt) + " servings of your recipe,you will need " + str(ing_one_oz) + " ounces of " /
+ str(ingredIEnt_one) + "," + str(ing_two_oz) + " ounces of " + str(ingredIEnt_two) + ",and " + str(ing_three_oz) /
+ " ounces of " + str(ingredIEnt_three))

我的输出为最后一行显示 TypeError: bad operand type for unary +: 'str'

解决方法

在对字符串执行操作时不能使用反斜杠。我相信这会解决您的问题。

ingredient_one = input("What is the first ingredient?: ")
ing_one_oz = int(input("How many ounces of this ingredient?: "))

ingredient_two = input("What is the second ingredient?: ")
ing_two_oz = int(input("How many ounces of this ingredient?: "))

ingredient_three = input("What is the third ingredient?: ")
ing_three_oz = int(input("How many ounces of this ingredient?: "))

servings_amt = int(input("How many servings would you like?: "))

ing_one_oz = ing_one_oz * servings_amt
ing_two_oz = ing_two_oz * servings_amt
ing_three_oz = ing_three_oz * servings_amt

print(
    f"In order to make {servings_amt} servings of your recipe,you will need {ing_one_oz} ounces of {ingredient_one},{ing_two_oz} ounces of {ingredient_two},{ing_three_oz} ounces of {ingredient_three}")

大佬总结

以上是大佬教程为你收集整理的这个 python 打印语句的最后一行中我连接的错误是什么?全部内容,希望文章能够帮你解决这个 python 打印语句的最后一行中我连接的错误是什么?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: