+ 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 !!")

22nd Nov 2024, 3:02 PM
Odobeatu Emmanuella
Odobeatu Emmanuella - avatar
6 Antworten
+ 1
name is not defined you need to convert the numbers to strings before concatenating there is a + missing in the 2nd print
22nd Nov 2024, 3:06 PM
Lisa
Lisa - avatar
+ 1
where did name come from?
22nd Nov 2024, 3:05 PM
Bob_Li
Bob_Li - avatar
+ 1
variable 'name' is not defined.
22nd Nov 2024, 3:13 PM
Alhaaz
Alhaaz - avatar
+ 1
I made a mistake Updated it now I can't get it to print the statement I want
22nd Nov 2024, 3:17 PM
Odobeatu Emmanuella
Odobeatu Emmanuella - avatar
+ 1
READ my COMPLETE comment.
22nd Nov 2024, 3:53 PM
Lisa
Lisa - avatar
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.
22nd Nov 2024, 7:35 PM
Lothar
Lothar - avatar