+ 4
Need help with a code
Hi, I've been struggling with this code for pratice 15.3 of python and i would appreciate it if u guys can help me out. Have tried different solutions but cant seems to solve it. Heres the question: Given the code above, output the input x repeated y times. Sample Input: awesome 3 Sample Output: awesomeawesomeawesome This is the code that i use: x = input("awesome") y = int(input("3")) print(x*y) Would gladly appreciate if u guys can help me out here. Keeps getting an error on this code
18 Respostas
+ 9
Somebody wrote code to take a string input and output it, repeated 10 times.
However, the code results in an error.
Fix the code to output the desired output.
so simple ,
x = input()
print(x*+10)
+ 4
Try without the prompt strings like this:
x = input() # read something like awesome from the user.
y = int(input()) # read something like 3 from the user.
print(x*y)
Passing a string to input causes it to print the string as if it is prompting the user for something specific. That probably causes the automated tests to fail since the output of:
awesome3
awesomeawesomeawesome
is not exactly the same as just:
awesomeawesomeawesome
If you run that as Python in Sololearn's Code Playground, just put this in the initial popup:
awesome
3
+ 2
Josh Greig Olga oh i get it now. My bad i didnt understand when u tried to explain why not to put in any parameters but now i understand. Thank you both so much
+ 2
x=input ()
y=int(input())
print(x*y)
+ 1
Haider wrote, "In python
X = input("")
Y = input("")
Print(X*Y)"
Response:
Haider, that won't work.
input returns a string even if it is a "3" and "awesome" * "3" would result in error.
Case is wrong for Print. It needs to be print.
Try it out for yourself and you'll see.
0
Good afternoon!
In your code, your input looks like this: input ("awesome"), int (input ("3")). When you run it, your program will print these lines.
Basically, when you add something within the input parentheses, it is a hint for the user what to enter.
The testing system does not need these hints; it only checks what the programs output.
For a testing system, the output in your program looks like this:
awesome
3
awesomeawesomeawesome
Remove everything from the parentheses at the input, and the program should work correctly.
x = input()
y = int(input())
print(x*y)
Hope this helped!
0
Josh Greig Olga Hello there, and thank you for your help, but when i do that i get an error that says undefined variable awesome and im really confused by it
0
zhi Hong, could you please share your code? By the way, did you try to send the code I added?
There should be no problems with variables.
0
Zhi wrote, "x = input(awesome)
y = int(input(3))
print(x*y)"
Response:
No. Remove the 3 and awesome there. Copy exactly what I shared. I added a comment only to explain. My comment wasn't asking you to add any parameters to the input function.
Here is what I shared again:
x = input() # read something like awesome from the user.
y = int(input()) # read something like 3 from the user.
print(x*y)
0
Wow i did it simple
print(x * 10)
0
Somebody wrote code to take a string input and output it, repeated 10 times.
However, the code results in an error.
0
X =input()
Print(x*10)
0
Test Case 1
x = "hello
print(x*10) -----> no Problem
Test Case 2 -----> OMG!!!
HELP!!!
0
Solved
x = input()
print(x*10)
That's it
0
i've been trying, i can do the the answer just like that.. BOOM
x = input('')
print(x*10)
- 1
In python
X = input("")
Y = input("")
Print(X*Y)
- 2
Olga i have inputed ur code this way:
x = input(awesome)
y = int(input(3))
print(x*y)
Not sure if this is what you mean? But i have gotten thr undefined variable when i key it in this way. Maybe im doing it wrong somewhere?