variables assignment | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

variables assignment

I have several problem this code, a,b = "85" Print (a) Output =8 Its become 8 But, a,b="65" Print (a*b) output = error Exception i thought its 30 Why this doing wrong python ? 👩‍🚀 This code, a,b=2,2.5 If a==b : Print ("yes") Not output

23rd Aug 2019, 10:00 PM
Teran Jay
Teran Jay - avatar
3 Answers
+ 5
The first block is correct, but the output isn't 8, it's "8" (a string, not an integer) In the second block you have a problem with multiplying "6" and "5" since they are both strings and not integers, use a,b = 6,5 instead to do so For the third part: you did this: a=2 and b=2.5 and then you check if 2 and 2.5 are the same. They clearly aren't, so the program will look for an else if/elif or else block. There is no elif or else so the program will just end with no output
23rd Aug 2019, 10:28 PM
Roel
Roel - avatar
+ 4
The second error had to do with data types. a = "6" // string b = "5" // string You can't multiply a string by another string. You have to first convert them to int by doing: int(a) * int(b) //outputs 30 Second "No Output" error ===================== In python, function names ARE case sensitive, so Print() ≠ print() You should use "print('yes')" Also, a = 2, b = 2.5 they aren't equal so the if block never even gets executed
23rd Aug 2019, 10:29 PM
Dlite
Dlite - avatar
+ 3
Thanks all
26th Aug 2019, 8:39 AM
Teran Jay
Teran Jay - avatar