0
Python Output Question!
Why is this the output?! Input: d="+" a= 6 y = 7 w = a-y print((w**(a**y))*d) Output: +
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
+ 1
w=-1
a**y=even number
-1**even number = 1. (-1 * -1 = 1)
1*'+' = +
+ 1
In your code, d is a string, NOT a number.
Multiplying a string by n returns that string n-times:
4 * 'd' - > dddd