0
Write a program to take x and y as input and output the string x, repeated y times. Sample Input hi 3 Sample Output hih
Pls someone help me i am stuck at this question 😑
19 Answers
+ 8
Hello :3,
Due to question
you have 2 different input,bone should be string, named x, another is integer, named y.
x = input() # input is already string as default
y = int(input()) # now sure it is integer
So the result is
print(x * y) # will give you y times string x
+ 5
x = input()
y = int(input())
print((x*y)[:y])
Use (x*y)[:y] for printing 'hih'
else only (x*y)
+ 3
x= input(" ")
y= int (input())
Output=(x*y)
Print(Output)
+ 3
print(input ()*3)
It will automatically typecast in string because the default is string in input
+ 3
print(input()*int(input))
That will do the work perfectly
The first input gets the string and the second inputs gets the number of times that the string is repeated
+ 2
If it has to print "hih" only, then try this
x=input()
y=int(input())
z=""
for i in range(1,y+1):
z=z+x
print(z[0:y])
+ 2
Guys we don't need to print "hi" three time. This is just sample text, I don't know what to fill in input 😕
+ 2
# Run in Ruby editor
def code(x,y)
p (x * y)[0...y]
# multipy string x, y times
# [0...y] is a range to select the string chars from 0 upto y
end
code "hi",3
# "hih"
+ 2
So the sample output would be hi 3 times: “hihihi”
So to break it down, first you need to store the user inputs in the variables x and y:
x = input()
y = input()
Since y is an int you need to convert it from the string input:
y = int(y)
If you want to store your output in a variable you can so:
output = x * y
Then print the output:
print(output)
Hopefuly breaking it down helps you see it better. You can write it more concisely like other answers like so:
print(input()*int(input()))
+ 1
x=input()
y=int(input())
z=""
for i in range(1,y+1):
z=z+x
print(z)
If it has to print hihihi
+ 1
Then try which I gave with respect to hih then see if it works or not.
I hope it works 🤞
+ 1
RIP u got em.. THC
+ 1
x = input()
y =input()
def mult_st(x, y):
return x*int(y)
mult_st()
+ 1
x=input()
y=int(input())
Print(x*y)
0
This is the Solution
x=input('')
y=int(input(''))
print(x*y)