Mozein
Mozein

Reputation: 807

function to output list is not working

I have a function that takes a parameter number integer, and outputs the list part of that number. so for example if we have

 List = ["Hello world", "james bond"] 

We create a function that takes a parameter number and outputs the right part of the list

This is the code I have

documentNum = input("What is the document number ?")
    createList(documentNum)

def createList(documentNum):
        List = ["Hello world", "james bond"] 
        print(List[documentNum])

so if we enter 1

I expect to get James bond

However I am getting instead that

List indices must be integers, not str

How to fix this problem ?

Upvotes: 1

Views: 48

Answers (1)

Alex Martelli
Alex Martelli

Reputation: 882691

Just use

documentNum = int(input("What is the document number ?"))

Upvotes: 4

Related Questions