You are not logged in. Please login at www.codechef.com to post your questions!

×

python help.!!!

i want to take integer input in an array ,and the integer input should be space separated.. how can i do it...

asked 08 Aug '14, 19:20

mintoo511's gravatar image

4★mintoo511
11
accept rate: 0%


you can use something like map function to do it:

array = map(int, input().split())

Hope it helps :).

link

answered 08 Aug '14, 19:26

ks2bmallik's gravatar image

2★ks2bmallik
854812
accept rate: 22%

edited 08 Aug '14, 19:32

thanx,but it is not helping.. i am using this for i in range (0,10): c[i]=int(input("")) it needs to press ENTER,but i want SPACE to input integer

(08 Aug '14, 19:32) mintoo5114★

Try this approach.

l=input()          #Accept everything in a string variable with spaces as you like
la=l.split(' ')    #the list la will contain all numbers separately as a string 
l=[]
for i in la:
    i=int(i)
    l.append(i)
print(l)          #This will print l which has integer elements
link

answered 26 Nov '16, 19:12

bkishan29's gravatar image

0★bkishan29
262
accept rate: 25%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×528
×141
×117

question asked: 08 Aug '14, 19:20

question was seen: 775 times

last updated: 26 Nov '16, 19:12