Question

Provide explanation about Iterations (python). Give examples and write a program.

Provide explanation about Iterations (python). Give examples and write a program.

Homework Answers

Answer #1

When a statement or any term is executed again and again then it's known as an iteration of the statement. And in python, there are various iterative methods which can be used for example:

1. for loop

suppose there is a list of array

a = [1,2,3,7,8]

so it prints the array in the order of

1

2

3

7

8

code for the same would be:

a = [1,2,3,7,8]

for i in arr:

print((i))

2. while loop

Another most wildly used loop is while loop

for example, if you want to print an integer up to a limit then you can do as follows

i = 7
while i < 34:
print(i)
i += 1

the output will be as follows:

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

For more detailed view of the iterations you can refer to the python documentation online.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write about strings and input in python. Explain with 2 examples.
Write about strings and input in python. Explain with 2 examples.
Write a Python program that plays a number guessing game with a human user. The human...
Write a Python program that plays a number guessing game with a human user. The human user will think of a number between 1 and 100, inclusive. Then the program has to guess what the user entered. keep track of the number of interaction it takes for the computer to guess the number. sample run: enter number to be guessed:88 output: you entered 88, and it took the program 3 iterations to guess.
[Python] what are the program solutions to the promts? Write a program to determine which word...
[Python] what are the program solutions to the promts? Write a program to determine which word is the shortest of the following: apple, banana, peach, plum, grapefruit. Write a program to determine the average number given in a list. The first line of your program should give a name to a list to be averaged: e.g numbers = [3,17,1,44,239]
Store Sales in Python Write a program that uses nested for loops to collect sales data...
Store Sales in Python Write a program that uses nested for loops to collect sales data per store and calculate the total and average sales for specified months. The program should first ask for the number of stores and the number of months. After each store iteration it should display the average and total sales for that store. After all iterations, the program should display the total and average sales for all the stores
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. Credit Score Annual Intrest Rate 500-649 %15.5 650-729 %9.5 730-800 %4.5 The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range, it asks him/her to enter a numeric...
Write about the branching programs (python). Please give an example of flow chart of conditional statements.
Write about the branching programs (python). Please give an example of flow chart of conditional statements.
****CODE IN PYTHON***** (Please replicate it EXACTLY as it is shown in the sample run) Write...
****CODE IN PYTHON***** (Please replicate it EXACTLY as it is shown in the sample run) Write a program where the user and the program/computer play a number guessing game. The program should prompt the user for a number (between 1 and 100, inclusive) then the program/computer has to guess what the user entered. Keep track of the number of iterations it takes for the computer to guess the number. Sample runs are shown below: Enter number to be guessed: 88...
Give an explanation of the difference between Jython and Python and why Jython was found.
Give an explanation of the difference between Jython and Python and why Jython was found.
Write the algorithm for this program using the C++ language (not python or java). The explanation...
Write the algorithm for this program using the C++ language (not python or java). The explanation needs to be at least 250 words. Explain everything throughly step by step. While there is a built-in pop_back function in the vector class, there is no built-in pop_front function. Suppose a program needs a pop_front function that will remove the first element from the vector. For example, if the original vector is [1, 2, 3, 4, 5], then after passing in this vector...
"Python strings are immutable" Explain in details what is that mean. Provide examples of strings in...
"Python strings are immutable" Explain in details what is that mean. Provide examples of strings in Python and how it can be used