Python Forum
HackerRank Problem: Code works on VS Code but not on the HackerRank site
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HackerRank Problem: Code works on VS Code but not on the HackerRank site
#1
Hi, I'm trying to solve this HackerRank problem: https://www.hackerrank.com/challenges/py...dd/problem

This is my code:

countries = set()
n = int(input())
for i in range(n):
    countries.add(input())
print(len(countries))
It works when I run it on VS Code, but gives the following error when I try to run the code on the HackerRank site:

Error:
Traceback (most recent call last): File "Solution.py", line 5, in <module> countries.add(input()) File "<string>", line 1, in <module> NameError: name 'UK' is not defined
What am I doing wrong here?
.
Reply
#2
Looks like they're using Python 2.x, as input used to do the same as eval, basically. Is there the option of using 3.x? If not, you'll need to use raw_input instead on Python 2.
Pnerd likes this post
Reply
#3
[How can I delete this post?]
Reply
#4
(Feb-28-2021, 06:22 PM)ndc85430 Wrote: Looks like they're using Python 2.x, as input used to do the same as eval, basically. Is there the option of using 3.x? If not, you'll need to use raw_input instead on Python 2.
Thanks. That was it. I chose Python 3 and tried again. And it worked. Thank you once again.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in output of a snippet code akbarza 2 354 Feb-28-2024, 07:15 PM
Last Post: deanhystad
  problem in running a code akbarza 7 624 Feb-14-2024, 02:57 PM
Last Post: snippsat
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 973 Nov-15-2023, 06:56 PM
Last Post: jst
  problem In using functools in a code akbarza 7 1,030 Oct-11-2023, 10:30 AM
Last Post: DeaD_EyE
  Problem with code / audio is playing randomly, not matching csv requirements Daniel_kcr 2 620 Sep-07-2023, 05:09 PM
Last Post: deanhystad
  Problem with my code slowing down and crashing SuchUmami 1 504 Jul-21-2023, 10:09 AM
Last Post: Gribouillis
  Code problem - probably easy fix? colin_dent 5 861 Jun-30-2023, 01:55 PM
Last Post: deanhystad
  Code works but doesn't give the right results colin_dent 2 709 Jun-22-2023, 06:04 PM
Last Post: jefsummers
  Code used to work 100%, now sometimes works! muzicman0 5 1,427 Jan-13-2023, 05:09 PM
Last Post: muzicman0
  python multiple try except block in my code -- can we shorten code mg24 10 6,079 Nov-10-2022, 12:48 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020