Computer Science
Predict the output
a, b, c = 2, 3, 4
a, b, c = a*a, a*b, a*c
print(a, b, c)
Python
Python Funda
25 Likes
Answer
Output
4 6 8
Explanation
a, b, c = 2, 3, 4
ā assigns initial value of 2 to a, 3 to b and 4 to c.a, b, c = a*a, a*b, a*c
ā a, b, c = 2*2, 2*3, 2*4
ā a, b, c = 4, 6, 8print(a, b, c)
ā prints values of a, b, c as 4, 6 and 8 respectively.
Answered By
10 Likes
Related Questions
What will be the output produced by following code ?
>>> print (print ("Hola", end = ""))
Carefully look at the following code and its execution on Python shell. Why is the last assignment giving error ?
>>> a = 0o12 >>> print(a) 10 >>> b = 0o13 >>> c = 0o78 File "<python-input-41-27fbe2fd265f>", line 1 c = 0o78 ^ SyntaxError : invalid syntax
The id( ) can be used to get the memory address of a variable. Consider the adjacent code and tell if the id( ) functions will return the same value or not(as the value to be printed via print() ) ? Why ?
[There are four print() function statements that are printing id of variable num in the code shown on the right.num = 13 print( id(num) ) num = num + 3 print( id(num) ) num = num - 3 print( id(num) ) num = "Hello" print( id(num) )
Consider below given two sets of codes, which are nearly identical, along with their execution in Python shell. Notice that first code-fragment after taking input gives error, while second code-fragment does not produce error. Can you tell why ?
(a)
>>> print(num = float(input("value1:")) ) value1:67 TypeError: 'num' is an invalid keyword argument for this function
(b)
>>> print(float(input("valuel:")) ) value1:67 67.0