Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Comment these two posts say why you are agree and ask some question to make the conversation flow Post 1 POST 1 Explain when to

Comment these two posts say why you are agree and ask some question to make the conversation flow

Post 1

POST 1

Explain when to use these different types of loops.

To explain, a loop is a repetitive task, and you already know how many times you need to do it. 

while loop 

For me, when I think of a while loop going upstairs, I know I have a task that needs to be done. It is a repetitive task until something changes, like a condition

How do you include a 'loop' structure in Python?

A loop is a repetitive task. For example, it is like asking someone to complete a task until a specific condition is met; in Python, the standard loops are for and while loops. 

How do you control a loop?

In controlling a loop, usually, there are rules to follow, for example, when it starts, how many times it can be treated, and when it should stop.

Provide sample code to demonstrate loops

In this example, to illustrate a loop 

friends = ["Alice," "Bob," "Charlie," "David," "Eva"]

For friends in friends:

    print("Hello, " + friend + "!")

In this example, the loop goes through each friend steadily instead of writing it individually. and it is like saying to to each to friend

POST 2

 For programming in python there are two loops that you have to memorize.  The first is for the loop which is used when we know how many times the loop will execute.  Second is the while loop and this is used when aren't sure how many times but we want to continue using it until a certain condition is true.  How we include a loop structure in python is writing a while loop and having it last until the condition is met.  There are three different types of control statements in python which are break statements, pass statements, and continue statements.  

 Sample code to demonstrate loops: 

 X=1

While x<9:

         Print (x)

         X=x+1

         If x==3:

         Continue 

Results:

1

2

3

4

5

 For i in range(10)

         If I ==5:

                  Break

         Print I 

Results:

0

1

2

3

4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Contemporary Engineering Economics

Authors: Chan S. Park

5th edition

136118488, 978-8120342095, 8120342097, 978-0136118480

More Books

Students also viewed these Algorithms questions

Question

What steps are involved with agreeing to terms with a seller?

Answered: 1 week ago