Computer Science, asked by TDCERDNRC, 6 months ago

find and remove
the errors
print ("Hello "+2)
print ("Hello" +2")
print ("Hello" * 2)​

Answers

Answered by allysia
2

Language:

Python

Errors (underlined) :

print ("Hello " +2)

print ("Hello" +2")

print ("Hello" * 2)​ #No error

Corrected:

print ("Hello " + "2") #returns Hello2  

print ("Hello" +"2")  #returns Hello2  

print ("Hello" * 2)​ #returns HelloHello

Explanation:

  • Datatype string and integer can't be added but they can be concatenated i.e joined like two strings. So what I did was converted 2's datatype from int to string by surrounding it with quotes.
  • Datatype sting can be multiplied with int. It repeats the units the number of times the number as in the above third line Hello is printed two times.

Similar questions