导入带有内部功能的大型功能

时间:2019-07-14 18:05:42

标签: python import

当卡路里s.py中的函数太复杂时,我导入的脚本出错。

我将所有功能都运行在卡路里数中,以确保它们能够按预期的方式工作。我将它们导入到Vicky.py。虽然我简单退出了,但是standardCalBurn函数可以正常工作。卡路里中的任何函数也引用了卡路里中的函数也不会在Vicky.py中运行。我收到一条错误消息,内容为:

Traceback (most recent call last):
  File "C:\Users\Marguerite\Documents\School\Programming\Python Class\Vicky.py", line 24, in <module>
    calories.user_command_menu_and_execution()
AttributeError: 'int' object has no attribute 'user_command_menu_and_execution'

由于某种原因,我无法将我的代码复制并粘贴到该网站中,该网站表示其格式不正确。我已经工作了两三天了。请帮助我在任何地方都找不到帮助。

calories.py:

def standardCalBurn(weight, height, age):
    cal_per_day=655+(4.3*weight)+(4.7*height)-(4.7*age)
    print('Daily intake calories to sustain weight:', cal_per_day, 'calories')
    return cal_per_day

Vicky.py:

cal_per_day=calories.standardCalBurn(weight, height, age)

以上工作正常。

calories.py:

def user_command_menu_and_execution():
    #give the user three options -- get user command
    calories_to_burn=int(input('Additional Calories:'))
    print('Choose one of three:')
    print('1 - time to burn additional calories running')
    print('2 - time to burn additional calories jogging')
    print('3 - time to burn additional calories walking')
    print('4 - New additional calorie amount')
    user_command=int(input('Enter command:'))
    while user_command != 4:    #loop until 4 is entered for new additional calorie amount
        if user_command not in user_command_list:  #invalid command
            print('Invalid command')
            user_command=int(input('Enter new command:'))
        elif user_command==1:       #time to burn additional calories running
                timeRequiredRun(calories_to_burn, weight)
        elif user_command==2:       #time to burn additional calories jogging
                timeRequiredJog(calories_to_burn, weight)
        elif user_command==3:
                timeRequiredWalk(calories_to_burn, weight)  #time to burn additional calories walking
        user_command=int(input('Enter new command:'))

0 个答案:

没有答案