洛谷题单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. 打印输出 结束

相关推荐
JieE2125 小时前
LeetCode 101. 对称二叉树|JS 递归 + 迭代双解法,彻底搞懂镜像判断
javascript·算法
金銀銅鐵10 小时前
[Python] 从《千字文》中随机挑选汉字
后端·python
cup1115 小时前
[技术复盘] Windows Python 打包实战:Nuitka 环境踩坑总结与 CI 自动化构建全指南
python·ai·环境变量·ci·nuitka·skill
aqi0017 小时前
15天学会AI应用开发(七)有了大模型为什么还要引入RAG
人工智能·python·大模型·ai编程·ai应用
金銀銅鐵19 小时前
用 Python 实现 Take-Away 游戏
python·游戏
copyer_xyf19 小时前
Agent 流程编排
后端·python·agent
copyer_xyf20 小时前
Agent RAG
后端·python·agent
copyer_xyf20 小时前
【RAG】向量数据库:milvus
后端·python·agent
copyer_xyf20 小时前
Agent 记忆管理
后端·python·agent