Today we will see the HackerRank Day 5 Solution in Python. The problem is named Loops which is part of 30 Days of code on HackerRank. Let’s get started!
Day 5: Loops Problem statement
We are given an integer n, our task is to print its first 10 multiples. Each multiple n x i should be printed on a new line 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
Explanation: Prints 10 lines of output; in which each line contains the result of 2 x i in the form, 2 x i = result.
You can solve the problem here.
HackerRank Day 5 Solution in Python
#!/bin/python3 import math import os import random import re import sys if __name__ == '__main__': n = int(input()) count=1 #Prints multiples of the given number upto 10 while count<=10: print(n,"x",count,"=",count*n) #Increment the count variable count+=1
Code Explanation
- First we get the input n from the user
- Then we initialise a count variable with 1
- Then in a loop we start printing the values with the given condition. That is the multiples of the given number upto 10
- Increment the count variable after printing each multiple
Also Read:
- HackerRank Day 8 Solution in Python: Dictionaries and Maps
- HackerRank Day 7 Solution in Python: Arrays
- HackerRank Day 6 Solution in Python: Let’s review
- HackerRank Day 5 Solution in Python: Loops
- HackerRank Day 4 Solution in Python: Class vs Instance
- HackerRank Day 3 Solution in Python: Intro to Conditional Statements
- HackerRank Day 2 Solution in Python: Operators
- HackerRank Day 1 Solution in Python: Data Types
- HackerRank Day 0 Solution in Python: Hello World
- HackerRank Day 29 Solution in Python: Bitwise AND
- HackerRank Day 28 Solution in Python: RegEx, Patterns, and Intro to databases
- HackerRank Day 27 Solution in Python: Testing
- HackerRank Day 26 Solution in Python: Nested Logic
- HackerRank Day 25 Solution in Python: Running Time and Complexity
- HackerRank Day 24 Solution in Python: More Linked Lists
- HackerRank Day 23 Solution in Python: BST Level Order Traversal
- HackerRank Day 22 Solution in Python: Binary Search Trees
- HackerRank Day 20 Solution in Python: Sorting
- HackerRank Day 19 Solution in Python: Interfaces
- HackerRank Day 18 Solution in Python: Queues and Stacks
- HackerRank Day 17 Solution in Python: More Exceptions
- HackerRank Day 16 Solution: Exceptions – String to Integer
- HackerRank Day 15 Solution in Python: Linked List
- HackerRank Day 13 Solution in Python: Abstract Classes
- HackerRank Day 14 Solution in Python: Scope
- HackerRank Day 12 Solution in Python: Inheritance
- HackerRank Day 11 Solution in Python: 2D Arrays
- HackerRank Day 10 Solution in Python: Binary Numbers