Posted by : at

Category : 30_Days_of_Code


This challenge asks you to print the first 10 integers of an integer n.

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

For this challenge, you can use a for loop or a while loop, both of which are introduced below.

for loops

A for loop loops over a certain number of iterations or through a list.

#looping through a number of iterations
for i in range(5): #loops from 0 UP TO 5 --> 0 1 2 3 4
    print(i, end = '')
01234  
#looping through a list
iter_list = ['You', 'can', 'loop', 'through', 'me']
for i in iter_list:
    print(i, end = ' ')
You can loop through me

It is common practice to use i and j to iterate through, but you can also use an underscore _ if you are not using the index anywhere.

for _ in range(4):
    print('Hello')
Hello
Hello
Hello
Hello

The loop will continue until it reaches the end of the range or a break statement. In the code below, once i == 5, it breaks out of the loop before it prints 5.

for i in range(10): #loops from 0 UP TO 10 --> 0 1 2 3 4 5 6 7 8 9
    if i == 5:
        break
    print(i)
0
1
2
3
4

while loops

A while loop continues until

Sample Solution:

class Person:
#!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
    n = int(input())
    for i in range(1,11): #from 1 UP to 11 (1-10)
        print(("{num} x {iter} = {mult}").format(num = n, iter = i, mult = n*i))
About

Data Scientist with B.S. Statistics (3.8 GPA, Cum Laude) from UCLA. Programming knowledge includes R, Python, SQL, Tableau, SAS and other data analysis tools.

Star