您可以使用用户输入将程序定向到python中的函数吗

问题描述

我正在使用 Python 开发税收计算器,我想知道是否可以将基于字符串的输入定向到函数。当我运行程序时,它除了初始输入之外什么都不做。我的代码片段如下:

class TaxCalculator():
type_of_pay = input(
    "Do you get paid hourly or salary? (Enter hourly or salary)")
if type_of_pay == "hourly":
    
    def hourly(self):
        rate = input("What do you get paid per hour")
        hours = input("Roughly how many hours do you work per week?")
        overtime = input(
            "Do you earn overtime? If so,answer with the rate,otherwise press enter.")

我不确定是否需要在其中包含 self 位,因为我不使用它(仍在学习 Python)。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)