I have to write a program which,
Given an integer, n , and n space-separated integers as input, create a tuple,t
, of those n
integers. Then compute and print the result of hash(t) .
Input Format
The first line contains an integer, n, denoting the number of elements in the tuple.
The second line contains n space-separated integers describing the elements in tuple t .
Output Format
Print the result of hash(t).
Problem in details at hackerrank
my code:
n = int(input())
list_B = []
value = input()
list = value.split()
s = len(list)
if s > n:
for x in range(n):
list_B.append(int(list[x]))
t = tuple(list_B)
print(hash(t))
Why my code gives wrong answer ?
I also collect the code which is correct from youtube
This code is,
n = int(input())
li = []
for x in input().split():
li.append(int(x))
t = tuple(li)
print(hash(t))
Why this code is correct?
This code fail to denoting the number of elements in the tuple and moreover here n is looks like kind of useless
Can you please make it clear?
Please…