30 Days of Code: HackerRank Solutions for Python (Day 5)
1 min readFeb 2, 2021
The one-stop spot for beginners.
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
.
#first we need to have an random integer, n to be multiplied 10 times.n = int(input())#then, we need a for loop multiplying the number, n with every number in from 1 to 10.
We know that we have to create a for loop with the given range of 1 to 10.
#then multiply the number, n, with every number in from 1 to 10.for i in range(1,11):
print (n, 'x', i, '=', i*n)#the print statement will show n, the random number given.
#x and =, are in '' so that the symbols are printed as a string.
# i*n will give you the answer to the multiplied numbers.
#the comma are used to seperate and join the string together.
This is a simple way to see clearly what the print statement output looks like as shown below.
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
Thanks for stopping by. If you want to see more solutions share and clap for more!