Day 5: Loops | 30 Days of Code | Hackerrank Solution

Hello coders, Today we will be solving Day 5: Loops problem which is the fifth day topic of Hacker Rank 30 Days of code.Loops helps in executi . . .

Day 5: Loops | 30 Days of Code | Hackerrank Solution 

Hello coders, 

Today we will be solving Day 5: Loops problem which is the fifth day topic of Hacker Rank 30 Days of code.

Loops helps in executing one or more statements up to a desired number of times.

After going through this post, you will get to know how to use loops in a program to get desired result.

So, Without Further Ado let's jump into the problem.

Day 5: Loops | 30 Days of Code | Hackerrank Solution


Objective 

In this challenge, we're going to use loops to help us do some simple math.

Task 

Given an integer, n, print its first 10 multiples. Each multiple n x i ( where 1 ≤ i ≤ 10 ) should be printed on a new line in the form: n x i = result.

Input Format 

A single integer, n.

Constraints 

  • 2 ≤ n ≤ 20

Output Format 

Print 10 lines of output; each line i ( where 1 ≤ i ≤ 10 ) contains the result of n x i in the form:

n x i = result 

Sample Input 

2

Sample Output 

2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20

Solution - Day 5: Loops

Python 3

#!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
    n = int(input())
    for i in range ( 1, 11 ):
        print ( n, "x", i, "=", n*i)        
Day 5 Loops in Python Hackerrank Solution
Day 5: Loops - Solution
Day 5 Loops in Python Hackerrank Solution
Day 5: Loops - Result


Conclusion 

This was the solution of Day 5: Loops problem. If you have any doubt regarding the problem ( Day:5 Loops ), feel free to contact in the Comment section.

Don't forget to Share it with your friends and Subscribe our Blog to receive latest updates related to coding.

Disclaimer: The above problem is generated by Hacker Rank but the solution is provided by Sloth Coders.

Happy Coding!!

A Sloth Who loves to Code.

Sloth Coders is a Learning Platform for Coders, Programmers and Developers to learn from the basics to advance of Coding of different langauges(python, Java, Javascript and many more).

Post a Comment