acmc 2022-03-30 18:56 采纳率: 91.8%
浏览 47
已结题

关于使用main函数的问题

如果才能使用main函数做到图中的问题啊,python函数的概念我还是不太理解。

img

img

  • 写回答

2条回答 默认 最新

  • hellobigorange 新星创作者: 人工智能技术领域 2022-03-30 19:05
    关注

    你return input()是想要做什么呀,这么写根本不会返回值呀,去掉input

    import random
    
    
    def main():
        score = random.randint(1, 100)
        result = determine_status(score)
        print(result)
        with open("result.txt", "a+") as f:
            f.write(result)
    
    
    def determine_status(score):
        if score < 0 or score > 100:
            return "\n{} is Invalid score".format(score)
        elif score >= 90:
            return "\n{} is Excellent score".format(score)
        elif score >= 50:
            return "\n{} is Pass score".format(score)
        else:
            return "\n{} is Bad score".format(score)
    main()
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 4月7日
  • 已采纳回答 3月30日
  • 创建了问题 3月30日