variables assignment | SoloLearn: Learn to code for FREE!


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

8/23/2019 10:00:17 PM

Teran Jay

4 Answers

New Answer


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


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


Thanks all