+ 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.

11th Jan 2022, 1:56 PM
Samuel Dimeji
Samuel Dimeji - avatar
11 Respostas
+ 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()
12th Jan 2022, 10:46 AM
SoloilSole
SoloilSole - avatar
+ 4
It is python2 code. In Python3 print is a function
11th Jan 2022, 6:21 PM
Oma Falk
Oma Falk - avatar
+ 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..
11th Jan 2022, 2:53 PM
Jayakrishna 🇼🇳
+ 1
What and where is that code? Show the code here... Otherwise how to find error? try to show your try..
11th Jan 2022, 2:00 PM
Jayakrishna 🇼🇳
+ 1
Samuel Akinnuoye Hint: You can use a for loop for that
11th Jan 2022, 2:06 PM
NEZ
NEZ - avatar
+ 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...
11th Jan 2022, 2:13 PM
Jayakrishna 🇼🇳
+ 1
Jayakrishna🇼🇳 thanks Your step gave me an hint I got the answer X= input () Print ("hello"*10)
11th Jan 2022, 2:48 PM
Samuel Dimeji
Samuel Dimeji - avatar
0
Nez: still a newbie don't even know what that is.
11th Jan 2022, 2:08 PM
Samuel Dimeji
Samuel Dimeji - avatar
0
Martin Taylor any clue to go about the question?
11th Jan 2022, 2:13 PM
Samuel Dimeji
Samuel Dimeji - avatar
0
Use for loop to print the string 10 times
12th Jan 2022, 3:16 AM
K RAMALAKSHMI
K RAMALAKSHMI - avatar