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

相关推荐
OOJO29 分钟前
c++---list介绍
c语言·开发语言·数据结构·c++·算法·list
别或许2 小时前
1、高数----函数极限与连续(知识总结)
算法
派大星~课堂2 小时前
【力扣-142. 环形链表2 ✨】Python笔记
python·leetcode·链表
田梓燊2 小时前
code 560
数据结构·算法·哈希算法
Thomas.Sir2 小时前
第一章:Agent智能体开发实战之【初步认识 LlamaIndex:从入门到实操】
人工智能·python·ai·检索增强·llama·llamaindex
笨笨饿2 小时前
29_Z变换在工程中的实际意义
c语言·开发语言·人工智能·单片机·mcu·算法·机器人
kobesdu3 小时前
综合强度信息的激光雷达去拖尾算法解析和源码实现
算法·机器人·ros·slam·激光雷达
艾为电子3 小时前
【技术帖】让接口不再短命:艾为 C-Shielding™ Type-C智能水汽防护技术解析
c语言·开发语言
weixin_413063213 小时前
记录 MeshFlow-Online-Video-Stabilization 在线稳像
算法·meshflow·实时防抖
ZTL-NPU3 小时前
Jetbrains开发ros
ide·python·pycharm·编辑器·ros·clion