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

相关推荐
XMYX-012 小时前
27 - Go string 字符串处理与格式化:从底层原理到工程实践
开发语言·golang
甄心爱学习12 小时前
【项目实训】法律文书智能摘要系统5
python·github
赏金术士12 小时前
Kotlin 协程面试题大全(Android 高频版)
android·开发语言·kotlin
高锰酸钾_12 小时前
计算机网络-网络层-路由算法与路由协议
计算机网络·算法·智能路由器
烟雨江南aabb12 小时前
Python第四弹:python进阶-匿名函数和内置函数
开发语言·python
智者知已应修善业12 小时前
51单片机4按键控制共阳LED霓虹灯切换1整体闪烁2流水下3流水上4间隔闪烁】2023-10-27
c++·经验分享·笔记·算法·51单片机
不瘦80斤不改名12 小时前
JavaScript 基础语法完全指南
开发语言·javascript·ecmascript
TE-茶叶蛋13 小时前
Java 8 引入的Stream API-stream()
java·windows·python
小陈的进阶之路13 小时前
Python系列课(9)——面向对象
开发语言·python
XW-ABAP13 小时前
SAP ABAP 实现类似百度谷歌搜索引擎基础算法之一的,编辑距离算法
算法