Python Forum

Full Version: HackerRank Problem: Code works on VS Code but not on the HackerRank site
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
.
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.
[How can I delete this post?]
(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.