Jump to content

How to code this in Python 3 Conditional loop(I'm newbie:-))


Pawelk198604

Recommended Posts

import turtle   

Dlugo_PiS = turtle.Pen()
Dlugo_PiS.shape("turtle")
Dlugo_PiS.forward(200)
Dlugo_PiS.left(120)    
Dlugo_PiS.forward(200)    
Dlugo_PiS.left(120) 
Dlugo_PiS.forward(200) 
Dlugo_PiS.left(60) 
turtle.done()    
turtle.bye()


 Want to write it simpler   import turtle   

Dlugo_PiS = turtle.Pen()    
Dlugo_PiS.shape("turtle")   
    while i in range(3)
       Dlugo_PiS.forward(200)   
       Dlugo_PiS.left(120) 
turtle.done()
turtle.bye()  



What i need to do to make it works  

Link to comment
Share on other sites

This is not python-specific.

For loops are used to iterate over a set number of things. Either a number of times, or (as is often used in Python) the members of a list.

While loops are used to  repeat the loop until some criterion is met.

So you can make a while loop into a for loop by adding an iteration statement into the loop, but it is better to just use the loop that is designed to iterate.

Edited by mikegarrison
Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...