[英]How can I make my main program appear first and how can I call my functions in my main program?
Right now I've tried making my main program the main "function" in my code.现在我已经尝试让我的主程序成为我代码中的主要“功能”。 But when I run it, the analysis bit comes up first which is not what i want.但是当我运行它时,分析位首先出现,这不是我想要的。 I want to make my code to do the following: output the main program so the user can input the marks total and input the marks scored in a test.我想让我的代码执行以下操作:输出主程序,以便用户可以输入总分并输入测试中的分数。
"Write a program that inputs a mark from the keyboard for sections of a project: 'analysis', 'design', 'implementation' and 'evaluation'. The program should output the total mark, the grade, and how many more marks were needed to get into the next mark band." “编写一个程序,从键盘输入项目部分的分数:'分析'、'设计'、'实施'和'评估'。该程序应该输出总分、成绩以及还有多少分需要进入下一个标记带。”
That was my task.那是我的任务。
def analysis():
print("Welcome to the analysis section")
marktotal=int(input("Input mark total which is out of /100"))
marks=int(input("Input marks"))
totalanalysis=print("You got",marks,"/",marktotal)
if marks > 80 or marks == 80:
print("A*")
elif marks > 67 or marks == 67:
print("A")
elif marks > 54 or marks == 54:
print("B")
elif marks > 41 or marks == 41:
print("C")
elif marks > 31 or marks == 31:
print("D")
elif marks > 22 or marks == 22:
print("E")
elif marks > 13 or marks == 13:
print("F")
elif marks > 4 or marks == 4:
print("G")
elif marks ==0:
print("U")
return
analysis()
def design():
print("Welcome to the design section")
marktotal=int(input("Input mark total which is out of /100"))
marks=int(input("Input marks"))
totalanalysis=print("You got",marks,"/",marktotal)
return
design()
def main():
selectedsection=str(input("What section would you like to grade?"))#main program starts here
if selectedsection =="analysis":
analysis()
elif selectedsection =="design":
print("design")
elif selectedsection =="implementation":
print("implementation")
elif selectedsection =="evaluation":
print("evaluation")
if __name__ == "__main__":
main()
不要调用函数,从 main 函数之外的代码中删除analysis()
和design()
。
I have taken your code and made some changes so that it is working.我已经使用了您的代码并进行了一些更改以使其正常工作。 I hope this helps you to find your problem.我希望这可以帮助您找到您的问题。
The part around your你周围的部分
if __name__ == "__main__":
looks strange.看起来很奇怪。 The main() function should be on its own line. main() 函数应该在它自己的行上。 Your posted code also had some indentation problems and the closing backticks should not be shown at the end.您发布的代码也有一些缩进问题,最后不应显示结束反引号。 I cannot change your post, because I have not enough reputation for that.我不能改变你的帖子,因为我没有足够的声誉。 The occurence of the function calls "analysis(), design() and main()" seem weird.函数调用“analysis()、design()和main()”的出现似乎很奇怪。 I have deleted analysis() and design().我已经删除了 analysis() 和 design()。 Also I have moved main() to its own line.我也将 main() 移到了自己的行。 Hard to say, if your original code is exactly the same as the posted code.很难说,如果您的原始代码与发布的代码完全相同。
def analysis():
print("Welcome to the analysis section")
marktotal=int(input("Input mark total which is out of /100"))
marks=int(input("Input marks"))
totalanalysis=print("You got",marks,"/",marktotal)
if marks > 80 or marks == 80:
print("A*")
elif marks > 67 or marks == 67:
print("A")
elif marks > 54 or marks == 54:
print("B")
elif marks > 41 or marks == 41:
print("C")
elif marks > 31 or marks == 31:
print("D")
elif marks > 22 or marks == 22:
print("E")
elif marks > 13 or marks == 13:
print("F")
elif marks > 4 or marks == 4:
print("G")
elif marks ==0:
print("U")
return
def design():
print("Welcome to the design section")
marktotal=int(input("Input mark total which is out of /100"))
marks=int(input("Input marks"))
totalanalysis=print("You got",marks,"/",marktotal)
return
def main():
selectedsection=str(input("What section would you like to grade?"))#main program starts here
if selectedsection =="analysis":
analysis()
elif selectedsection =="design":
print("design")
elif selectedsection =="implementation":
print("implementation")
elif selectedsection =="evaluation":
print("evaluation")
if __name__ == "__main__":
main()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.