【hackerrank】-Day 3: Intro to Conditional Statements

24 篇文章 0 订阅
24 篇文章 0 订阅

30-conditional-statements
Objective
In this challenge, we’re getting started with conditional statements. Check out the Tutorial tab for learning materials and an instructional video!

Task
Given an integer, , perform the following conditional actions:

If is odd, print Weird
If is even and in the inclusive range of to , print Not Weird
If is even and in the inclusive range of to , print Weird
If is even and greater than , print Not Weird
Complete the stub code provided in your editor to print whether or not is weird.

Input Format

A single line containing a positive integer, .

Constraints

Output Format

Print Weird if the number is weird; otherwise, print Not Weird.

Sample Input 0

3
Sample Output 0

Weird
Sample Input 1

24
Sample Output 1

Not Weird
Explanation

Sample Case 0:
is odd and odd numbers are weird, so we print Weird.

Sample Case 1:
and is even, so it isn’t weird. Thus, we print Not Weird.


Current Buffer (saved locally, editable)

#!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
    N = int(input())
    if N < 1 or N > 100:
        print('N < 1 or N > 100')
    if N % 2 != 0:
        print('Weird')
    # 说明需求是2到5之间的偶数打印Not Weird,包含2和5,所以注意是range(2, 6)
    if N % 2 == 0 and N in range(2, 6):
        print('Not Weird')
    # 说明需求是6到20之间的偶数打印Weird,包含6和20,所以注意是range(6, 21)
    if N % 2 == 0 and N in range(6, 21):
        print('Weird')
    if N % 2 == 0 and N > 20:
        print('Not Weird')

Congratulations!

You have passed the sample test cases. Click the submit button to run your code against all the test cases.

Testcase 0 Testcase 1
Input (stdin)
3
Your Output (stdout)
Weird
Expected Output
Weird

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
/* 全局样式 */ body { font-family: Arial, sans-serif; font-size: 16px; color: #333; margin: 0; } a { color: #333; text-decoration: none; } a:hover { color: #555; } ul, ol { margin-top: 0; margin-bottom: 10px; } ul li, ol li { margin-left: 20px; } /* 头部样式 */ header { color: #fff; padding:0 0 0 0; } .container { max-width: 1660px; margin: 0 auto; padding: 0 20px; } #hero { background-image: url(QMZYWY/images/wy.jpg); background-size: cover; background-position: center; color: #fff; text-align: center; padding: 100px 0; } h1 { margin: 0; font-size: 32px; } nav { display: flex; justify-content: flex-end; } nav ul { list-style: none; margin: 0; padding: 0; display: flex; } nav li { margin-right: 20px; } nav a { color: #fff; text-decoration: none; padding: 5px; border-radius: 5px; transition: background-color 0.2s ease; } nav a:hover { background-color: #555; } /* 英雄介绍样式 */ .hero-intro { background-color: #fff; padding: 40px 0; } .hero-intro-text { margin-bottom: 20px; } .hero-intro-image { text-align: center; } .hero-intro-image img { max-width: 100%; height: auto; } /* 游戏攻略样式 */ .game-strategy { background-color: #f5f5f5; padding: 40px 0; } .game-strategy p { margin-bottom: 20px; } /* 页脚样式 */ footer { background-color: #222; color: #fff; padding: 10px 0; } footer p { margin: 0; text-align: center; } /* 响应式样式 */ @media screen and (max-width: 768px) { .container { padding: 0 10px; } h1 { font-size: 24px; } nav { justify-content: center; } nav li { margin-right: 10px; } .hero-intro { padding: 20px 0; } .hero-intro-text { text-align: center; } .hero-intro-image { margin-top: 20px; } } @media screen and (min-width: 768px) { .hero { background-image: url('QMZYWY/images/wy.jpg'); } }在此代码中加入网页背景图片响应式
最新发布
06-12

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值