Hanwool Codes RSS Tag Admin Write Guestbook
전체 글 (45)
2023-01-19 17:06:46

Arithmetic Operators | HackerRank

 

Arithmetic Operators | HackerRank

Addition, subtraction and multiplication.

www.hackerrank.com

 

Goal

 

1. Read two integers from STDIN.

2. Solve tasks to use arithmetic operators. 

 

 

Solution

 

You can read values by using input() function. The important thing is to convert input() value into integer type because Input() function returns string value from input. 

 

After read two integer values, you can calculate vaules for each task.

 

# Arithmetic Operators

if __name__ == '__main__':
    a = int(input())
    b = int(input())
    
    sum = a + b
    difference = a - b
    product = a * b
    
    print(sum)
    print(difference)
    print(product)
2023-01-19 16:57:00

Python If-Else | HackerRank

 

Python If-Else | HackerRank

Practice using if-else conditional statements

www.hackerrank.com

 

Goal

 

You need to print "Weird" if the number is weird in under condition. Otherweise, print "Not Weird". 

 

 

Solution

You can follow what conditions say, then it would be easy.

 

# Python If-Else

import math
import os
import random
import re
import sys


if __name__ == '__main__':
    n = int(input().strip())
    
    if (n % 2) !=0 : 
        print('Weird')
    else:
        if (n >=2 and n <=5):
            print('Not Weird')
        
        elif (n >=6 and n <=20):
            print('Weird')
            
        else:
            print('Not Weird')

 

2023-01-19 16:49:23

Say "Hello, World!" With Python | HackerRank

 

Say "Hello, World!" With Python | HackerRank

Get started with Python by printing to stdout.

www.hackerrank.com

 

Goal

 

Print "Hello, World!" to stdout. 

 

Solution

 

You can use print function to print the specificed message. 

 

# Say "Hello, World!" With Python

if __name__ == '__main__':
    print("Hello, World!")


Hanwool Codes. Designed by 코딩재개발.