专业编程基础技术教程

网站首页 > 基础教程 正文

Python If-Else 挑战(python if else elif经典例题和答案)

ccvgpt 2024-07-29 13:40:49 基础教程 10 ℃

今天带来"HackerRank" 的 Python 挑战 关卡 2, If-Else. (附带原文章翻译) 帖子末端会提供 关卡2的传送门,有需要的同学也可以注册挑战一下。Task (题目)Given an integer, , perform the following conditional actions:一个特定的整数 n, 执行以下的条件行动:If is odd, print Weird如果 n 是奇数,打印 Weird (奇怪)If is even and in the inclusive range of to , print Not Weird如果 n 是偶数而且在3-5的范围,打印 Not Weird (不奇怪)If is even and in the inclusive range of to , print Weird如果 n 是偶数而且在6-20的范围内,打印 WeirdIf is even and greater than , print Not Weird如果 n 是偶数而且大于 20,打印 Not WeirdInput Format输入格式A single line containing a positive integer, n.单行但包含一个正整数,nConstraints条件 n 大于或等于1,同时,n 小於或等于100Output Format输出格式Print Weird if the number is weird; otherwise, print Not Weird.打印 Weird 如果数字是属于 奇怪的,否则,打印 Not Weird 。Sample Input 00号例子输入

[Python] 纯文本查看 复制代码

Python If-Else 挑战(python if else elif经典例题和答案)

Sample Output 00号例子输出

[Python] 纯文本查看 复制代码

Sample Input 11号例子输入

[Python] 纯文本查看 复制代码

Sample Output 11号例子输出

[Python] 纯文本查看 复制代码

Explanation解释Sample Case 0: n = 3, n is odd and odd numbers are weird, so we print Weird.0号例子: n = 3, n 是奇数而且奇数是属于 奇怪的,所以我们打印 Weird 。Sample Case 1: n = 24, n > 20 and n is even, so it isn't weird. Thus, we print Not Weird.1号例子: n = 24, n 大于 20 而且 n 是偶数,所以它不属于 奇怪的。如此,我们打印 Not Weird 。理解完题目就准备开始咯!!!~

需要关卡地址的请私信我哦

愿各位加油,一起努力学习。

Tags:

最近发表
标签列表