BASHA TECH
[HackerRank][Python] Loop 본문
728x90
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.
Example
The printout should look like this:
n = 3
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30
Input Format
A single integer, .
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.
#!/bin/python3
import math
import os
import random
import re
import sys
if __name__ == '__main__':
n = int(input().strip())
for i in range(1,11):
result = n * i
print(f"{n} x {i} = {result}")
This code reads an integer n from the user, then uses a for loop to print the first 10 multiples of n, one per line. The loop iterates over the numbers 1 to 10, and for each number i, it calculates n * i and prints the result in the desired format.
728x90
반응형
'Activity > Coding Test' 카테고리의 다른 글
[HackerRank][Python] Arrays (0) | 2023.04.17 |
---|---|
[HackerRank][Python] Let's Review (1) | 2023.04.17 |
[HackerRank][Python] Class vs Instance (0) | 2023.04.12 |
[HackerRank][Python] Intro to Conditional Statements (0) | 2023.04.11 |
[HackerRank][Python] Operators (0) | 2023.04.11 |
Comments