+ 1
Python problem
This is a question Write a program to take x and y as input and output the string x, repeated y times. In first case x=cool Y=2 And second case X=a Y=8 Now i want to run this both program on one page what should i do? I am stucked on a practice page because app is asking outputs for both case's
18 Answers
+ 2
x = input()
y = int(input())
print(x*y)
Though the above code is bad as you would want to ensure y is a number otherwise it will crash so this is what I recommend:
x = input()
y = input()
if y.isdigit():
y = int(y)
print(x*y)
else:
print("Please enter a number for second input")
+ 1
x = input()
y = int(input())
print(f"X:{x} Y:{y} resultX:{x*y}")
+ 1
How to solve this problem:
#Input will be x,so
x = input()
#Next is, y which will be an integer because x will be repeated y times.
y = int(input())
#Now, x has to be repeated y times. Remember, in Mathematics, when we repeat a number any given times, we multiply it. So here, I will use this .
print (x*y)
If anybody finds my solution wrong, please correct.
+ 1
Basil Thanks!! š I got it.
0
Yes
0
X="cool"
Y=8
Print(x*int(y))
Is it right??
0
Can you do it for me here?
0
this is going looong:
func = lambda x,y : x*y if (type(x)==str and type(y)== int) else None
print(func('cool',2))
print(func('a',8))
print(func(1,2))
# this should do the magic
# just use 'func' as the challenge wants and that's it (ā¢āæā¢).
0
y = int(input())
x = int(input())
for i in range(y):
print(x)
0
Basil Thanks for correcting my solution but I think that y can't be a string because x can't be repeated a string times.
How will it crash?Please explain.
0
Gursimran Kaur As an input you can enter anything you want, so for example, if you enter 'six' instead of 6 for the second input, it would crash because string 'six' cannot be converted to an integer unless it is a digit like 6.
Otherwise glad I could help.
0
Gursimran Kaur Awesome
0
What is """ .isdigit()"""