Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saili-shinde/hackerrank
https://github.com/saili-shinde/hackerrank
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/saili-shinde/hackerrank
- Owner: saili-shinde
- Created: 2022-10-12T05:01:58.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-10-12T05:35:45.000Z (about 2 years ago)
- Last Synced: 2023-08-03T06:50:30.689Z (over 1 year ago)
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Hackerrank solutions
## Python code solution
### Say "Hello, World!" With Python
Here is a sample line of code that can be executed in Python:
```
print("Hello, World!")
```
You can just as easily store a string as a variable and then print it to stdout:
```
my_string = "Hello, World!"
print(my_string)
```
The above code will print Hello, World! on your screen. Try it yourself in the editor below!**Input Format**
You do not need to read any input in this challenge.
**Output Format**
Print Hello, World! to stdout.
**Sample Output 0**
```
Hello, World!
```
***code***
```
print("Hello, World!")```
### Python If-Else
**Task**
Given an integer,`n`,perform the following conditional actions:If`n`is odd, print Weird
If`n`is even and in the inclusive range of to`2`,`5` print Not Weird
If`n`is even and in the inclusive range of to`6`,`20`print Weird
If`n`is even and greater than`20`, print Not Weird**Input Format**
A single line containing a positive integer,`n`.
**Constraints**
`1<=n<=100`
**Output Format**
Print Weird if the number is weird. Otherwise, print Not Weird.
**Sample Input 0**
```
3
```
**Sample Output 0**
```
Weird
```
**Explanation 0**`n=3`
`n`is odd and odd numbers are weird, so print Weird.
**Sample Input 1**
```
24
```
**Sample Output 1**
```
Not Weird
```
**Explanation 1**`n=24`
`n>20`and`n` is even, so it is not weird.
***code***
```
import math
import os
import random
import re
import sysif __name__ == '__main__':
n = int(raw_input().strip())
if n%2!=0:
print('Weird')
elif n%2==0 and 2<=n<=5:
print('Not Weird')
elif n%2==0 and 6<=n<=20:
print('Weird')
elif n%2==0 and n>20:
print('Not Weird')```