mercredi 26 août 2020

Same code, 2 different outputs? (Pycharm vs Hackerrank)

https://www.hackerrank.com/challenges/py-if-else/problem

Given an integer, n, perform the following conditional actions:

  • If n is odd, print Weird
  • If n is even and in the inclusive range of 2 to 5, print Not Weird
  • If n is even and in the inclusive range of 6 to 20, print Weird
  • If n is even and greater than 20, print Not Weird

When I try to solve the problem above, if I define "n" as 24 for example, Hacker rank says it's wrong because it should output "Not Weird" instead of "Weird".

But when I run it in PYCHARM, the output is "Not Weird".

I have changed the PYTHON version to PYTHON3 in Hacker rank, so, that shouldn't be a problem.

Here's my code:

n = 24

if n % 2 == 1:
    print("Weird")
elif n % 2 == 0 and n in range(2, 5):
    print("Not Weird")
elif n % 2 == 0 and n in range(6, 20):
    print("Weird")
else:
    print("Not Weird")

Aucun commentaire:

Enregistrer un commentaire