Hi
I have a function dela ( ) and I want to call it by user (c) times, but I get an error.

Traceback (most recent call last):
File "C:/Python25/My programs/extra_b.py", line 21, in <module>
for j in range (c):
TypeError: range() integer end argument expected, got str.

if __name__ == "__main__":
    c= raw_input (" please enter an integer  ")
    for j in range (1,c):
        dela (x)

Thanks a lot for help.

c= raw_input (" please enter an integer ") Say you enter the number 4. What is c after that? It is the string "4", and the range() function does not accept strings in for j in range (1,c): . Quickest way out: for j in range (1,int(c)): which will convert the string "4" to the integer 4 and away you go. Problem here is if the user enters something not an integer, say the letter X, then int(c) will throw an exception and your program will stop. Lots of ways to handle that, but it's a different problem for another time.

Thank you very much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.