+ 2
What's wrong with this code ? ( Beginner)
#addition of numbers name= input() num1= int(input()) #pick a number num2= int(input()) #pick a number sum = num1 + num2 print (sum) print (name + " , " + num1 + " + " + num2 " = " + sum + " !") print ("eurika !!")
6 Respuestas
+ 1
name is not defined
you need to convert the numbers to strings before concatenating
there is a + missing in the 2nd print
+ 1
where did name come from?
+ 1
variable 'name' is not defined.
+ 1
I made a mistake
Updated it now
I can't get it to print the statement I want
+ 1
READ my COMPLETE comment.
0
Odobeatu Emmanuella ,
to get the output string in a more simpler way, we can use a so called `f-string` (string interpolation). this needs a bit learning new things, but as you can see in the samples, the definition of the output is less confusing, and we do not need to convert numerical values to a string first.
this link leads to a tutorial about string handling:
https://stackabuse.com/guide-to-strings-in-JUMP_LINK__&&__python__&&__JUMP_LINK/
to get to the section where f-strings are explained, go to the menue of the browser, select `search in page` and insert this:
`Introduction to f-strings`
you will find explanations and code samples that you can use / modify for your own purpose.