0
x = input()
reverseuserinput = x[::-1]

if x == reverseuserinput:
    print("true")
else:
    print("false")

My code works in VS but when I submit it on leetcode it doesnt work and comes up with the error: "'int' object has no attribute 'getitem'"

It says there is a problem in line 2 but I dont know how to solve.

John Gordon
  • 29,573
  • 7
  • 33
  • 58
0zyu
  • 1
  • 3
  • 2
    Sounds like leetcode is using a **very old** version of python, where `input()` was a very different function than it is today. – John Gordon Feb 26 '23 at 15:00
  • Ok, ill just leave it. Thankyou! – 0zyu Feb 26 '23 at 15:02
  • 1
    As John Gordon said - they use python 2.7. You can check it by running `import sys; print(sys.version)`. If you want to understand the difference, check https://stackoverflow.com/q/4915361/4046632 And frankly, I would consider moving to different platform if I were you – buran Feb 26 '23 at 15:14
  • Try `x = str(input())` in the first line – sourin_karmakar Feb 26 '23 at 15:27
  • 2
    @sourin If the OP is using Python 2.7, they should not be using `input` in the first place; they should use `raw_input` instead. – chepner Feb 26 '23 at 15:31
  • just tried the code, it works perfectly fine on python `3.11`.... – D.L Feb 26 '23 at 15:55
  • Thanks it works now, just realised I was on the wrong version of python for leetcode. Works fine on python 3. Thanks for all the replies. I'm new to this – 0zyu Feb 26 '23 at 16:00
  • @buran What better platform? LeetCode were the first site I know who already had Python 3.10, like a year ago already. I even occasionally abused it to test new Python functionality for SO answers. – Kelly Bundy Feb 28 '23 at 04:11
  • @KellyBundy, I admit I am not familiar with leetcode. I just visited their homepage and checked the code editor widget there. I didn't know you can click playground and get more language choices, incl. python3. I dicovered it now. Anyway, I find it odd at best that they keep as the default version python2 and not python3. – buran Feb 28 '23 at 06:55

0 Answers0