3或5整除规则输出Apple与Pie
类型:程序题

题目说明

给定一个整数 num,从 1 到 num 按照下面的规则返回每个数:

  1. 如果这个数被 3 整除,返回 'Apple'。

  2. 如果这个数被 5 整除,返回 'Pie'。

  3. 如果这个数能同时被 3 和 5 整除,返回 'ApplePie'。

  4. 如果这个数既不能被 3 也不能被 5 整除,返回这个数字的字符串格式。

n=int(input("请输入一个数字:"))
results=[]
for i in range(1,①):
    if ②:
        results.append("ApplePie")
    elif i%3==0:
        results.append("Apple")
    elif i%5==0:
        results.append("Pie")
    else:
        results.append(③)
print(results)

评分标准

  1. n+1(3分)

  2. i%3==0 and i%5==0(4分)

  3. str(i)(3分)

代码编辑器 加载中...
留空使用题目默认限制
{{resultStatus.text}}
正在加载运行记录...
乐编题库AI助手
人工客服
微信扫码联系客服
历史对话
{{ s.title || '未命名对话' }}
{{ s.created_at }}
暂无历史对话
我能帮助你什么?