Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You've got several problems.</p> <ol> <li><code>sin(x)</code> will never be greater than 1 or less than -1, so it makes no sense to check <code>y</code> up to 100. Your whole loop structure is wrong.</li> <li>If you want to match <code>x</code> to integer values of <code>sin(x)</code> (1, 0, and -1), you need to multiply <code>x</code> by <code>math.pi/2</code></li> <li>Because of the way floating point math works, <code>0==sin(pi)</code> or <code>0==sin(2*pi)</code> will not be true, you need to check something like <code>-0.01 &lt; sin(pi) &lt; 0.01</code>.</li> <li><code>create_oval</code> need two different pairs of <code>x, y</code> -- an upper left and lower right. You're passing it the same value for both points, so you would only ever see maybe a single dot if you did get to this point.</li> <li>The <code>x=0</code> is unnecessary, as a new <code>range(100)</code> will be created for <code>x</code> every time you go to a new <code>y</code> value.</li> </ol> <p>Edit: @eryksun pointed out in a comment that #4 may be your intention. If so, that part is right, and the whole thing makes more sense -- it looks like you're trying to plot the sine curve. It also means you don't necessarily want to multiply <code>x</code> by <code>math.pi / 2</code>.</p> <p>If that's the case, your code could be something like (changing as little as possible):</p> <pre><code>from Tkinter import * import math main=Tk() w=Canvas(main, height=100, width=100) w.grid(row=0, column=0) for x in range(100): # this makes the sine curve y-value # stretch from 0 to 100 instead of -1 to 1 y = 49.5 - math.sin(x) * 49.5 w.create_oval(x, y, x, y) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload