+ 5

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
Ella
Ella - avatar
14 ответов
+ 9
If you're not familiar with f-string, just don't use + in your print. Comma-separate them instead. You can't add strings and ints, but you can pass them as comma separated arguments in print. Also, don't use sum as variable name. Sololearn does not give you warnings, but Pydroid and other decent IDEs will warn you that sum is a Python method name and you are redefining it. You don't want to do that. name= input() num1= int(input()) #pick a number num2= int(input()) #pick a number total = num1 + num2 print(total) print(name, "," , num1, "+", num2, "=", total, "!") print("eurika !!") but yes, as Lothar suggested, learn about f-strings. It will give you much more control in printing and string formatting.
22nd Nov 2024, 11:40 PM
Bob_Li
Bob_Li - avatar
+ 8
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
+ 7
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
+ 5
variable 'name' is not defined.
22nd Nov 2024, 3:13 PM
Alhaaz
Alhaaz - avatar
+ 5
Rizwan Hanif I recommend you start with the html and web development course or python as they are the most simple and easier languages to learn. Give it a try ! If you need any help , we're all here to support you but give it a try yourself first :)
24th Nov 2024, 11:39 AM
~AZ~ {LESS ACTIVE}
~AZ~ {LESS ACTIVE} - avatar
+ 4
Thanks everyone
23rd Nov 2024, 5:21 AM
Ella
Ella - avatar
+ 4
Rizwan Hanif , what kind of help do you need? this forum is meant for coding related questions and answers. > so if you have any coding related questions or douts you can post them here. please make sure to follow the forum guidelines.
23rd Nov 2024, 8:59 PM
Lothar
Lothar - avatar
+ 4
Its 21 days
25th Nov 2024, 10:27 AM
✧Bhavik✧[MORE THAN LESS ACTIVE]
✧Bhavik✧[MORE THAN LESS ACTIVE] - avatar
+ 3
where did name come from?
22nd Nov 2024, 3:05 PM
Bob_Li
Bob_Li - avatar
+ 3
READ my COMPLETE comment.
22nd Nov 2024, 3:53 PM
Lisa
Lisa - avatar
+ 3
Rizwan Hanif The messaging option gets open after 30 days of when you join sololearn https://www.sololearn.com/Discuss/2668917/?ref=app
25th Nov 2024, 9:31 AM
~AZ~ {LESS ACTIVE}
~AZ~ {LESS ACTIVE} - avatar
+ 3
The problem is that you are adding two variables with opposite values. The name variable is of string type and the number variables are of int type and these two types of variable values ​​cannot be added together... To solve the problem, you can convert int type to string
25th Nov 2024, 11:58 AM
‎مهدی پناهی🇮🇷
‎مهدی پناهی🇮🇷 - avatar
+ 2
I made a mistake Updated it now I can't get it to print the statement I want
22nd Nov 2024, 3:17 PM
Ella
Ella - avatar
+ 1
idk
9th Dec 2024, 3:07 PM
Артём Чонтян
Артём Чонтян - avatar