洛谷题单2-P5712 【深基3.例4】Apples-python-流程图重构

题目描述

小 B 喜欢吃苹果。她今天吃掉了 x x x 个苹果。英语课上学到了 apple 这个词语,想用它来造句。如果她吃了 1 个苹果,就输出 Today, I ate 1 apple.;如果她没有吃,那么就把 1 换成 0;如果她吃了不止一个苹果,别忘了 apple 这个单词后面要加上代表复数的 s。你能帮她完成这个句子吗?

输入格式

输入一行一个自然数 x x x,表示吃掉的苹果数。

输出格式

根据题目要求输出。

输入输出样例

输入

复制代码
1

输出

复制代码
Today, I ate 1 apple.

方式

代码

python 复制代码
class Solution:
    @staticmethod
    def oi_input():
        """从标准输入读取数据"""
        x = int(input())
        return x

    @staticmethod
    def oi_test():
        """提供测试数据"""
        return 1

    @staticmethod
    def solution(x):
        if x == 1 or x == 0:
            print(f"Today, I ate {x} apple.")
        else:
            print(f"Today, I ate {x} apples.")


oi_input = Solution.oi_input
oi_test = Solution.oi_test
solution = Solution.solution

if __name__ == '__main__':
    '''用oi_test()接受数据,然后传入solution'''
    x = oi_test()
    # x = oi_input()
    solution(x)

流程图

是 否 开始 主函数调用 获取输入x x == 0 或 1? 格式化单数句子
Today, I ate {x} apple. 格式化复数句子
Today, I ate {x} apples. 打印输出 结束

相关推荐
心中有国也有家2 小时前
GE图引擎深度解析——CANN的计算图优化与执行引擎
人工智能·pytorch·python·学习·numpy
地平线开发者3 小时前
profiler debug 工具用法与高一致性策略
算法·自动驾驶
卷毛的技术笔记3 小时前
告别硬编码!Spring AI Alibaba 实现 AI Agent 智能工具调用(Tool Calling)
java·人工智能·后端·python·spring·ai编程
编程大师哥3 小时前
匿名函数 lambda + 高阶函数
java·python·算法
isyangli_blog3 小时前
OpenDayLight (Carbon 版本) 启动与组件安装
开发语言·php
vb2008113 小时前
FastAPI APIRouter
开发语言·python
Benszen3 小时前
KVM虚拟化解决方案
开发语言·perl
会编程的土豆3 小时前
Go 语言反射(Reflection)详解
开发语言·后端·golang
東雪木3 小时前
多线程与并发编程 专属复习笔记
java·开发语言·笔记·java面试
adrninistrat0r4 小时前
Java调用链MCP分析工具
java·python·ai编程