(Python question)

What is a real-life example of directions that have a “for loop” and directions that have a “while loop”? (Hint: think about cooking.)

Respuesta :

Wolfyy

Hey!

---------------------------------------------------

Definition:

A "for loop" is something used for repeating things over a list of items. For instance, a list or a dictionary.

Code:

colors = ["red", "green", "blue"]

for x in colors:

 print(x)

---------------------------------------------------

Definition:

A "while loop" is is something used for carrying out a set of lines that are true.

Code:

n = 1

while i < 4:

 print(n)

 n += 1

---------------------------------------------------

Real-Life Example:

A real-life example would if I was a manager or boss for a company say that everyone was off a certain day. Like, if I said everyone was off for Christmas the 25th. If I had 1000 employees that would take a very long time to send an email to everyone. Instead of sending an email to everyone I can program code that uses "for loops" and "while loops" to create a message and send it to everyone.

---------------------------------------------------

Hope This Helped! Good Luck!

PSN03

Yo sup??

A real life example for 'for loop' and a 'while loop' would be

imagine if I opened a new burger shop.

we plan to issue a 'Thank you' message to the first 2000 customers and a 'Never to see you again' for all.

So for doing the first part ie to issue a 'thank you' message I will use a for loop because I am aware of the number of iterations whereas for the latter part ie to issues the 'never to see you again' message I would use a while loop cause I am not aware about the customers that are gonna visit my shop.

Hope this helps

PS: in which language is brainly written??