简体   繁体   中英

for project euler number 4 i am just wondering what is wrong with my code. have been knacking my brain and i do not know how, this is on python

x=100
y=100
z=str(x*y)
k=[]
while x<=999 and y<=999:
    if z==int(z[::-1]):
        k.insert(z)
    x+=1
    y+=1
print(k)

this just produced an empty bracket, i want to know why and how i can fix this. thanks

if z==int(z[::-1]):

This condition is always false because z never changes in the loop, and because z is a string so it will never equal an int

After fixing that your code will still fail because x and y are always equal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM