Computing desk | ||
---|---|---|
< April 25 | << Mar | April | May >> | April 27 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
Here's the relevant Python function:
def is_power(a,b): if a%b > 0: return False else: if a/b == b: return True else: if a/b/b == b: return True else: while a > 1 or a == 1: a = a/b is_power(a,b)
When I type "print(is_power(2,16))" or "print(is_power(3,81))" or print(is_power(4,256))", the program prints out "None" (instead of "True"). In other words, there's an issue with powers of four. I previously had this problem with powers of three in this Python function, but then I changed the function a bit, fixed the issue with the powers of three, but ended up having a problem with powers of four instead. Anyway, how do I fix my Python function here?
Basically, I want to return True if a is a power of b but return False otherwise. Futurist110 ( talk) 06:16, 26 April 2019 (UTC)
None
because there is no return
under the last else
, so when the loop terminates there is no value specified to be returned. --
CiaPan (
talk) 10:59, 26 April 2019 (UTC)
def is_power(a,b): # return true if a is a power of b, else false
if b == 0:
return False
while b%a == 0:
b //= a
return (b == 1)
def is_power(a,b): # return true if a is a power of b, else false
if b == 0:
return (a == 0)
if b == 1:
return (a == 1)
if a == 0:
return False
while a % b == 0:
if a == b:
return True
a //= b
return False
Thank you very much for your assistance, guys! Futurist110 ( talk) 01:46, 8 May 2019 (UTC)
Please visit this question in Webmasters Stackexchange. — Preceding unsigned comment added by 103.199.26.76 ( talk) 17:35, 26 April 2019 (UTC)
Is there iPhone app that when installed list me the app installed on iPhone that are compatible with iPad? -- 151.49.89.141 ( talk) 18:17, 26 April 2019 (UTC)
This is more of the technical side of it, does the normal blocking function block a specific username and password from logging in, or does it block the user's IP? What if the user logs out and edits via IP spoofing? (Or create new account(s) from different IPs)? And what if the user is vandalising (or whatever they're doing) cross-wiki? It feels like determined users will always find some way to evade a block or ban. Rob3512 chat? what I did 19:17, 26 April 2019 (UTC)
Computing desk | ||
---|---|---|
< April 25 | << Mar | April | May >> | April 27 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
Here's the relevant Python function:
def is_power(a,b): if a%b > 0: return False else: if a/b == b: return True else: if a/b/b == b: return True else: while a > 1 or a == 1: a = a/b is_power(a,b)
When I type "print(is_power(2,16))" or "print(is_power(3,81))" or print(is_power(4,256))", the program prints out "None" (instead of "True"). In other words, there's an issue with powers of four. I previously had this problem with powers of three in this Python function, but then I changed the function a bit, fixed the issue with the powers of three, but ended up having a problem with powers of four instead. Anyway, how do I fix my Python function here?
Basically, I want to return True if a is a power of b but return False otherwise. Futurist110 ( talk) 06:16, 26 April 2019 (UTC)
None
because there is no return
under the last else
, so when the loop terminates there is no value specified to be returned. --
CiaPan (
talk) 10:59, 26 April 2019 (UTC)
def is_power(a,b): # return true if a is a power of b, else false
if b == 0:
return False
while b%a == 0:
b //= a
return (b == 1)
def is_power(a,b): # return true if a is a power of b, else false
if b == 0:
return (a == 0)
if b == 1:
return (a == 1)
if a == 0:
return False
while a % b == 0:
if a == b:
return True
a //= b
return False
Thank you very much for your assistance, guys! Futurist110 ( talk) 01:46, 8 May 2019 (UTC)
Please visit this question in Webmasters Stackexchange. — Preceding unsigned comment added by 103.199.26.76 ( talk) 17:35, 26 April 2019 (UTC)
Is there iPhone app that when installed list me the app installed on iPhone that are compatible with iPad? -- 151.49.89.141 ( talk) 18:17, 26 April 2019 (UTC)
This is more of the technical side of it, does the normal blocking function block a specific username and password from logging in, or does it block the user's IP? What if the user logs out and edits via IP spoofing? (Or create new account(s) from different IPs)? And what if the user is vandalising (or whatever they're doing) cross-wiki? It feels like determined users will always find some way to evade a block or ban. Rob3512 chat? what I did 19:17, 26 April 2019 (UTC)