+ 2
Somebody wrote code to take a string input and output it, repeated 10 times. However, the code results in an error.
Python beginner help me with the code please. My code x=input ("hello"*10) Print x I am getting error message.
10 Answers
+ 5
Samuel Akinnuoye,
in your code:
x = input()
print("hello" * 10) x has no impact on output, because there is no x inside print fuction.
if you use input(), your code should be like:
x = input() # whatever it is, can be "hello" , "apple", "cake" ect.
print(x * 10)
But if you already know your variable like:
x = "hello"
print(x * 10)
But as you see, it has nothing to do with input()
+ 4
It is python2 code. In Python3 print is a function
+ 2
Samuel Akinnuoye But your code not using input value.
You can get same by just
print("hello " * 10)
For different text to print, use
x=input()
print(x * 10)
Hope it helps..
You're welcome..
+ 1
What and where is that code? Show the code here... Otherwise how to find error?
try to show your try..
+ 1
Samuel Akinnuoye
Hint: You can use a for loop for that
+ 1
Always Notify, if you edited any...
Samuel Akinnuoye
x=input ("hello"*10) #this will ask you to enter input by showing "hello" 10 times ,
Your any input will be stored in x.
Print x, # this is syntax error..
It should be
print(x)
As you need 10 times then use
print(x*10)
Try these and reply if any error again...
+ 1
Jayakrishna🇮🇳 thanks
Your step gave me an hint
I got the answer
X= input ()
Print ("hello"*10)
0
Nez: still a newbie don't even know what that is.
0
Martin Taylor any clue to go about the question?
0
Use for loop to print the string 10 times