What is the error in my python code -


you given integer nn on 1 line. next line contains nn space separated integers. create tuple of nn integers. let's call tt. compute hash(t) , print it.

note: here, hash() 1 of functions in __builtins__ module.

input format first line contains nn. next line contains nn space separated integers.

output format print computed value.

sample input

2

1 2

sample output

3713081631934410656

my code

a=int(raw_input()) b=() i=0 in range (0,a):     x=int(raw_input())     c = b + (x,)      i=i+1  hash(b)     

error: invalid literal int() base 10: '1 2'

there 3 errors can spot: first, for-loop not indented. second, should not adding 1 - for-loop automatically. thirds - , error thrown - raw_input reads entire line. if reading line '1 2', cannot convert int.

to fix problem, suggest doing:

line = tuple(map(int,raw_input().split(' '))) 

this takes raw input, splits list, makes list ints, turns list tuple.

in fact, can scrap entire loop. answer problem in 2 lines of code:

raw_input()#to rid of first line, not need print hash(tuple(map(int,raw_input().split(' ')))) 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -