简体   繁体   English

进程以退出代码 0 结束

[英]Process finishes with exit code 0

I have the code, it works but it does not produce the graph it is supposed to.我有代码,它可以工作,但它不会生成它应该生成的图形。 I have matplotlib installed.我安装了 matplotlib。

import matplotlib.pyplot as plt


def weight_reduction():
    current_weight = float(input("Enter your current weight (in pounds): "))
    desired_weight = float(input("Enter your desired weight (in pounds): "))
    weight_loss = current_weight - desired_weight
    dietary_habits = float(input("Enter your current caloric intake (in calories): "))
    exercise = float(input("Enter your current exercise level (1-5): "))
    daily_deficit = dietary_habits - exercise
    try:
        days = int(input("Enter the number of days you would like to track your weight loss: "))
    except ValueError:
        print("Please enter a valid number of days.")
        days = int(input("Enter the number of days you would like to track your weight loss: "))
    weight_loss_per_day = weight_loss / days
    daily_caloric_intake = dietary_habits - weight_loss_per_day * 3500 / 7
    x = [i for i in range(days)]
    y = [current_weight - i * weight_loss_per_day for i in range(days)]
    plt.plot(x, y)
    plt.xlabel("Days")
    plt.ylabel("Weight (in pounds)")
    plt.title("Weight Reduction Progress")
    plt.show()

I tried the code and expected a graph.我尝试了代码并期望得到一个图表。

Here is a suggestion: After defining your function weight_reduction , call it without intendation.这里有一个建议:在定义你的 function weight_reduction之后,无意中调用它。 I assume you have just defined but not called the function.我假设您刚刚定义但未调用 function。

So at first define your function as you already did:所以首先像你已经做的那样定义你的 function :

import matplotlib.pyplot as plt

def weight_reduction():
   ...
   ...
   plt.show()

And then call the function you defined (you tell the program to execute the steps you declared) just below the function definition:然后在 function 定义下方调用您定义的 function(您告诉程序执行您声明的步骤):

weight_reduction()

In case you alrady did try this, please provide more information in your question.如果您已经尝试过此操作,请在您的问题中提供更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM