Do you really need to print out sys.version
? I really see no reason why you need to do this. Remove:
import sys
print(sys.version)
Just do this:
digits_str = input("Enter no. of digits in multipliers : ")
digits = int(digits_str)
In one line:
digits = int(input("Enter no. of digits in multipliers : "))
Remove the semicolon:
max_plier = int(("9" * (digits+1))[:digits]); # Maximum n-digit number for eg. if digits = 3, max_plier = 999
^
(There are some other PEP8 violations in your code)
This actually doesn't avoid repetitive calculations, it does nothing:
max_plier = z # To avoide repetitive calcualtions.
Once you have created a range
object it is immutable, changing maxplier
won't change the range. Just be sure to replace max_plier
in your inner loop with z
.
Again:
global pallindromes
Is unneeded get rid of it entirely.
I would abstract this into a function is_palindrome
:
if (str(product) == str(product)[::-1]) :
pallindromes.append(product)
Hmmm, interestingly enough I would have suggested doing a more "arithmetic" approach to determining if a number is a palindrome, this answer this answer seems to suggest that indeed your solution is the fastest. But this isn't necessarily true for every language, be sure to profile stuff! (Well, it looks like you did so good job!)
Do you really need to print out sys.version
? I really see no reason why you need to do this. Remove:
import sys
print(sys.version)
Just do this:
digits_str = input("Enter no. of digits in multipliers : ")
digits = int(digits_str)
In one line:
digits = int(input("Enter no. of digits in multipliers : "))
Remove the semicolon:
max_plier = int(("9" * (digits+1))[:digits]); # Maximum n-digit number for eg. if digits = 3, max_plier = 999
^
(There are some other PEP8 violations in your code)
This actually doesn't avoid repetitive calculations, it does nothing:
max_plier = z # To avoide repetitive calcualtions.
Once you have created a range
object it is immutable, changing maxplier
won't change the range. Just be sure to replace max_plier
in your inner loop with z
.
Again:
global pallindromes
Is unneeded get rid of it entirely.
I would abstract this into a function is_palindrome
:
if (str(product) == str(product)[::-1]) :
pallindromes.append(product)
Hmmm, interestingly enough I would have suggested doing a more "arithmetic" approach to determining if a number is a palindrome, this answer seems to suggest that indeed your solution is the fastest. But this isn't necessarily true for every language, be sure to profile stuff! (Well, it looks like you did so good job!)
Do you really need to print out sys.version
? I really see no reason why you need to do this. Remove:
import sys
print(sys.version)
Just do this:
digits_str = input("Enter no. of digits in multipliers : ")
digits = int(digits_str)
In one line:
digits = int(input("Enter no. of digits in multipliers : "))
Remove the semicolon:
max_plier = int(("9" * (digits+1))[:digits]); # Maximum n-digit number for eg. if digits = 3, max_plier = 999
^
(There are some other PEP8 violations in your code)
This actually doesn't avoid repetitive calculations, it does nothing:
max_plier = z # To avoide repetitive calcualtions.
Once you have created a range
object it is immutable, changing maxplier
won't change the range. Just be sure to replace max_plier
in your inner loop with z
.
Again:
global pallindromes
Is unneeded get rid of it entirely.
I would abstract this into a function is_palindrome
:
if (str(product) == str(product)[::-1]) :
pallindromes.append(product)
Hmmm, interestingly enough I would have suggested doing a more "arithmetic" approach to determining if a number is a palindrome, this answer seems to suggest that indeed your solution is the fastest. But this isn't necessarily true for every language, be sure to profile stuff! (Well, it looks like you did so good job!)
Do you really need to print out sys.version
? I really see no reason why you need to do this. Remove:
import sys
print(sys.version)
Just do this:
digits_str = input("Enter no. of digits in multipliers : ")
digits = int(digits_str)
In one line:
digits = int(input("Enter no. of digits in multipliers : "))
Remove the semicolon:
max_plier = int(("9" * (digits+1))[:digits]); # Maximum n-digit number for eg. if digits = 3, max_plier = 999
^
(There are some other PEP8 violations in your code)
This actually doesn't avoid repetitive calculations, it does nothing:
max_plier = z # To avoide repetitive calcualtions.
Once you have created a range
object it is immutable, changing maxplier
won't change the range. Just be sure to replace max_plier
in your inner loop with z
.
Again:
global pallindromes
Is unneeded get rid of it entirely.
I would abstract this into a function is_palindrome
:
if (str(product) == str(product)[::-1]) :
pallindromes.append(product)
Hmmm, interestingly enough I would have suggested doing a more "arithmetic" approach to determining if a number is a palindrome, this answer seems to suggest that indeed your solution is the fastest. But this isn't necessarily true for every language, be sure to profile stuff! (Well, it looks like you did so good job!)