如何循环包含多个函数的代码?

2024-10-02 14:18:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在设计一个程序来计算你的薪水。它涉及多个函数,我需要做的是按照调用顺序循环所有这些函数。以下是我的无循环代码:

def showIntro():
    intro = print('Hello! I will take your input and calculate your 
weekly paycheck before 
taxes.')

showIntro()

def get_rate():
    rate = float(input('Enter hourly rate: '))
    return rate

def get_hours():
    hours = float(input('Enter hours worked: '))
    if hours >= 41:
        print('Your base hours including overtime is: ' , hours)
    if hours <= 40:
        print('Your hours entered were: ' , hours)
    return hours

def get_paycheck(rate , hours):
    paycheck = rate  * hours
    if hours >= 41:
        print('Your weekly paycheck with over time is: ' , rate * hours)
    if hours <=40:
        print('Your weekly paycheck is: ' , rate * hours)
    return (rate , hours)

rate = get_rate()
hours = get_hours()

get_paycheck(rate,hours)

结束代码

我如何循环它,使它返回showIntro()并重复自身


Tags: 函数代码inputyourgetreturnifrate