K
K
K1r1ll41k2022-01-04 17:52:24
Python
K1r1ll41k, 2022-01-04 17:52:24

A beginner in programming, I decided to create a program that creates a graph of the root function. There was an error in the tkinter module. How to fix?

Here is the code that should create the graph:

``````from tkinter import Tk, Canvas, Frame, BOTH
from math import *
from re import *

win = Tk()
win.geometry('500x500')
win.resizable(False, False)
c = input()
x = []
if search(r'\bsqrt\b', c):
a = search(r'\d*', c)
for i in range(501):
x.append((i+3))
x.append(400 - (sqrt(i)*a))

canvas = Canvas()
canvas.create_line(3, 400, 503, 400, fill = 'red', width = 2)
canvas.create_line(3, 400, 3, 0, fill = 'red', width = 2)
canvas.create_polygon(x, outline = 'red', fill = 'white', width = 2)
canvas.pack(fill=BOTH, expand=1)

win.mainloop()``````

The following error occurs when entering 2sqrt:

``````Traceback (most recent call last):
File "C:\Python32\aert", line 23, in <module>
canvas.create_polygon(x, outline = 'red', fill = 'white', width = 2)
File "C:\Python32\lib\tkinter\__init__.py", line 2191, in create_polygon
return self._create('polygon', args, kw)
File "C:\Python32\lib\tkinter\__init__.py", line 2166, in _create
cnf = args[-1]
IndexError: tuple index out of range``````

How to fix a mistake, if not difficult - with an explanation