Python Forum
How to use positional arguments - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to use positional arguments (/thread-4593.html)



How to use positional arguments - RedSkeleton007 - Aug-29-2017

I tried to test my program (I'm using IDLE), but I got the following error in Python 3.6.2 Shell:
TypeError: textinput() missing 1 required positional argument: 'prompt'

#WhileLoopNameSpiral

import turtle
t = turtle.Pen()
turtle.bgcolor("black")
colors = ["red", "yellow", "blue", "green", "orange",
          "purple", "white", "brown", "gray", "pink"]
family =[] #empty list for family names

name = turtle.textinput("It's time to build a list of family names.",
                        "Enter a name, or just hit [ENTER] to quit:")
#keep asking for names
while name != "":
    family.append(name)
    name = turtle.textinput("Enter another name,or hit [ENTER] to quit:")

#draw a spiral of the names on the screen:
for x in range(100):
    t.pencolor(colors[x%len(family)])#rotate through the colors
    t.penup()#do not draw the regular spiral lines
    t.forward(x*4)#just move the turtle to the next spiral angle
    t.pendown()#draw the next family member's name
    t.write(family[x%len(family)], font = ("Arial", int((x+4)/4), "bold"))
    t.left(360/len(family) + 2)#turn left for our spiral
The shell says the error is in line 15 of my code. This is a syntax error I presume?


RE: How to use positional arguments - ichabod801 - Aug-29-2017

turtle.textinput takes two positional positional parameters, a title for the pop up window and a prompt detailing the response needed. You only provided one, so turtle assume it was the title, and wanted to know where the prompt was.

It's always good to check the documentation on errors like this: https://docs.python.org/3.5/library/turtle.html#turtle.textinput