+ 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

21st Feb 2022, 9:06 PM
Aslam Pathan
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")
23rd Feb 2022, 2:56 PM
Basil
Basil - avatar
+ 1
x = input() y = int(input()) print(f"X:{x} Y:{y} resultX:{x*y}")
22nd Feb 2022, 12:10 PM
CodeStory
CodeStory - avatar
+ 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.
23rd Feb 2022, 10:19 AM
Aurora Borealis
Aurora Borealis - avatar
+ 1
Basil Thanks!! 😊 I got it.
23rd Feb 2022, 3:17 PM
Aurora Borealis
Aurora Borealis - avatar
0
Yes
21st Feb 2022, 9:13 PM
Aslam Pathan
0
X="cool" Y=8 Print(x*int(y)) Is it right??
21st Feb 2022, 9:21 PM
Aslam Pathan
0
Can you do it for me here?
21st Feb 2022, 9:23 PM
Aslam Pathan
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 (•‿•).
21st Feb 2022, 10:07 PM
Ervis Meta
Ervis Meta - avatar
0
y = int(input()) x = int(input()) for i in range(y): print(x)
23rd Feb 2022, 1:00 PM
Saad Khan
Saad Khan - avatar
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.
23rd Feb 2022, 3:07 PM
Aurora Borealis
Aurora Borealis - avatar
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.
23rd Feb 2022, 3:10 PM
Basil
Basil - avatar
23rd Feb 2022, 3:17 PM
Basil
Basil - avatar
0
What is """ .isdigit()"""
23rd Feb 2022, 8:02 PM
DiFenz