python - Python3新手需要建议
问题描述
大家好,总的来说,我是编码和后端计算的新手。我已经做了大约 3 周,并认为我会尝试编写我的第一个应用程序。我的大多数应用程序都运行良好,但我无法弄清楚如何让系统接受新输入并将其应用于我的函数 loop() 运行后。请帮忙!
from os import sys
def say_bye():
print("GoodBye!")
sys.exit()
def loop():
print()
print("Would you like to enter another value?")
choice2 = input('y/n: ')
if choice2 == 'y':
print()
amount = float(input("enter another price: "))
rate = float(input("tax rate: "))
print()
return in_page(), tot_with_tax_exit(), print(tot_with_tax()), loop()
else:
return say_bye()
def tot_with_tax():
tax = (amount * rate)
total = ("Your total after tax is", tax + amount)
return total
def tot_with_tax_exit():
if amount == int(0):
print('would you like to exit')
choice = input('y/n?: ')
if choice == 'y':
print()
return say_bye()
else:
return tot_with_tax()
def in_page():
print()
print("Welcome to the tax tool!")
print()
print("Please enter your total price, and tax rate.")
in_page()
amount = float(input("enter price: "))
tot_with_tax_exit()
rate = float(input("tax rate: "))
print(tot_with_tax())
loop()
解决方案
您必须将值传递给函数 to_with_tax() 这里是代码,其中包含使其工作的更改。
from os import sys
def say_bye():
print("GoodBye!")
sys.exit()
def loop():
print()
print("Would you like to enter another value?")
choice2 = input('y/n: ')
if choice2 == 'y':
print()
amount = float(input("enter another price: "))
rate = float(input("tax rate: "))
print()
return in_page(), tot_with_tax_exit(), print(tot_with_tax(amount, rate)), loop()
else:
return say_bye()
def tot_with_tax(amount, rate):
tax = (amount * rate)
total = ("Your total after tax is", tax + amount)
return total
def tot_with_tax_exit():
if amount == int(0):
print('would you like to exit')
choice = input('y/n?: ')
if choice == 'y':
print()
return say_bye()
else:
return tot_with_tax()
def in_page():
print()
print("Welcome to the tax tool!")
print()
print("Please enter your total price, and tax rate.")
in_page()
amount = float(input("enter price: "))
tot_with_tax_exit()
rate = float(input("tax rate: "))
print(tot_with_tax(amount, rate))
loop()
推荐阅读
- json - 如何从 JSON 对象中获取特定值,例如名称?
- jdbc - 将 Pentaho 数据集成与 Oracle 自治数据仓库连接起来
- ruby-on-rails - Rails cancancan 获取特定用户的记录
- scala - 如何在 Scala 中将杂乱无章的文本文件转换为 Array[String]?
- php - 当我使用关系和分页时,我在使用 laravel 获取数据时遇到问题
- c - 如何从任意虚拟地址转储内存,忽略 SIGSEGV
- database - 以spring JPA为代表的重叠关系
- javascript - 使用给定的动态数据更新选择选项
- ios - 如何以及何时保存用户 APN 令牌以进行 firebase 消息传递?
- javascript - 如何在 Enter 按键上单击按钮