0

Python Output Question!

Why is this the output?! Input: d="+" a= 6 y = 7 w = a-y print((w**(a**y))*d) Output: +

30th Apr 2018, 2:58 PM
stephanie
stephanie - avatar
3 Antworten
+ 4
because: ( w ** (a**y)) * d will do this. First: evaluate a**y = 6**7 = 279 936 Second: do w ** 279 936 = -1 ** 279 936 = 1 (-1 to an even power is 1) Third: ( w ** (a**y)) * d = 1 * "+" = "+" You can multiply int by Strings. It just gives you the string the int number of times
30th Apr 2018, 3:12 PM
cyk
cyk - avatar
+ 1
w=-1 a**y=even number -1**even number = 1. (-1 * -1 = 1) 1*'+' = +
30th Apr 2018, 3:13 PM
Louis
Louis - avatar
+ 1
In your code, d is a string, NOT a number. Multiplying a string by n returns that string n-times: 4 * 'd' - > dddd
30th Apr 2018, 8:33 PM
Johannes
Johannes - avatar