Repeat With Dash

Repeat With Dash

Easy Python Data Types 9 views
Explanation Complexity

Problem Statement

Word w and integer n are provided. Output w repeated n times, joined with '-' (dash). If n is 0 output empty.

Input Format

• First line: String w (single word, no spaces)

• Second line: Integer n

Output Format

• Print the word w repeated n times, joined with -

• If n = 0, print nothing (empty output)

Example

hi 4
hi-hi-hi-hi

Constraints

• 0 ≤ n ≤ 10^5

• 1 ≤ length of w ≤ 10^5

Concept Explanation

Input:
w = "hello"
n = 3

Repeat word 3 times and join with -

Result:
hello-hello-hello

If n = 0, output is empty.

Step-by-Step Explanation

1.Read string w.

2.Read integer n.

3.If n == 0, print nothing.

4.Otherwise:

• Create a list containing w repeated n times.

• Join the list using '-'.join().

5.Print the result.

Concept Explanation

Input:
w = "hello"
n = 3

Repeat word 3 times and join with -

Result:
hello-hello-hello

If n = 0, output is empty.

Step-by-Step Explanation

1.Read string w.

2.Read integer n.

3.If n == 0, print nothing.

4.Otherwise:

• Create a list containing w repeated n times.

• Join the list using '-'.join().

5.Print the result.

Input / Output Format

Input Format
• First line: String w (single word, no spaces)

• Second line: Integer n
Output Format
• Print the word w repeated n times, joined with -

• If n = 0, print nothing (empty output)
Constraints
• 0 ≤ n ≤ 10^5

• 1 ≤ length of w ≤ 10^5

Examples

Input:
hi 4
Output:
hi-hi-hi-hi

Example Solution (Public)

Python
import sysnp=sys.stdin.read().strip().split()nif not p: sys.exit(0)nw=p[0]nn=int(p[1])nif n<=0:n  sys.stdout.write('')nelse:n  sys.stdout.write('-'.join([w]*n))

Official Solution Code

import sysnp=sys.stdin.read().strip().split()nif not p: sys.exit(0)nw=p[0]nn=int(p[1])nif n<=0:n  sys.stdout.write('')nelse:n  sys.stdout.write('-'.join([w]*n))
Please login to submit solutions.
Editor
Output

                                        
Please login to submit solutions.