1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Firdavs [7]
2 years ago
9

Lab Goal : This lab was designed to demonstrate the similarities and differences in a for loop and a while loop.Lab Description

: Write a for loop that accomplishes the same goal as a while loop and write a while loop that accomplishes the same goal as a for loop. Finally, write a loop your way: write either a for loop or a while loop that produces the appropriate output.Sample Output :***** While Loop String Cleaner ****I am Sam I am with the letter a removed by a while loop is I m Sm I m***** For Loop String Cleaner ****I am Sam I am with the letter a removed by a for loop is I m Sm I m***** For Loop Common Divisor ****The for loop determined the common divisors of 528 and 60 are12 6 4 3 2***** While Loop Common Divisor ****The while loop determined the common divisors of 528 and 60 are12 6 4 3 2***** My Total Loop My Way ****The total of even numbers from 1 to 1000 using a for loop is 250500The total of even numbers from 1 to 1000 using a while loop is 250500*Only one of the two output statements are required. For extra credit, do both
Computers and Technology
1 answer:
Mandarinka [93]2 years ago
8 0

Answer:

See Explanation

Explanation:

Required:

Use for and while loop for the same program

<u>(1) String Cleaner</u>

#For Loop

name = "I am Sam"

result = ""  

<em>for i in range(0, len(name)):  </em>

<em>    if name[i]!= 'a':  </em>

<em>        result = result + name[i] </em>

print(result)

#While Loop

name = "I am Sam"

result = ""  

<em>i = 0 </em>

<em>while i < len(name): </em>

<em>    if name[i]!= 'a':  </em>

<em>        result = result + name[i] </em>

<em>    i+=1 </em>

print(result)

<u>(2): Common Divisor</u>

#For Loop

num1 = 528

num2 = 60

div = num2

if num1 > num2:

   div = num1

<em>for i in range(2,div):</em>

<em>    if num1%i == 0 and num2%i==0:</em>

<em>        print(i,end = " ")</em>

print()

#While Loop

num1 = 528

num2 = 60

div = num2

if num1 > num2:

   div = num1

i = 2

<em>while i <div:</em>

<em>    if num1%i == 0 and num2%i==0:</em>

<em>        print(i,end = " ")</em>

   i+=1

The iterates statements show the difference in the usage of both loops.

For the for loop, the syntax is:

<em>for [iterating-variable] in range(begin,end-1)</em>

<em>-------</em>

<em>---</em>

<em>--</em>

<em />

For the while loop, the syntax is:

<em>while(condition)</em>

<em>-------</em>

<em>---</em>

<em>--</em>

You might be interested in
What is a gamer?
mixer [17]

Answer:

It is <em>definitely </em>D.

Explanation:

I am a gamer myself so this question is easy for me. It's slim to none to be wrong when you view my answer!!!

7 0
2 years ago
When a table is displayed in datasheet view, each column represents a select one:
Ksivusya [100]
The answer a. record in the table.
5 0
3 years ago
Let's consider a long, quiet country road with houses scattered very sparsely along it. (We can picture the road as a long line
Rus_ich [418]

Answer:

Follows are the solution to these question:

Explanation:

A simple gullible algorithm is present. Let h mark the house to the left. Then we put a base station about 4 kilometers to the right. Now delete and repeat all the houses protected by this base station. In this algorithm, they can simply be seen to position baselines at b1, . . , bk as well as other algorithms (which may be an optimum algorithm) at b'_{1}, \ . . . . . . ,b'_{k'}  and so on. (from left to right)   b_1 \geq b'_{1},\ \  b_2 \geq b'_{2} That's why k \leq k'.

7 0
2 years ago
15. Select the correct answer.
givi [52]

Answer:

Pixel dimensions

Explanation:

measure of height and width of a image in pixels

3 0
2 years ago
What are some strategies that you can use to prepare to file taxes each year? What would be the benefits of these strategies
lisov135 [29]

<u>Answer:</u>

It is a <em>special type of window which displays the list of projects </em>and their related files. It allows the <em>developer to easily manage the files</em> and also enable us to <em>create folders and sub folders and organize the project well.</em>

<u>Explanation:</u>

We can <em>add or remove files from the project if necessary</em> permissions are available. You can drag and move the solution explorer within the window.

It has options to make the <em>window appear</em> at a particular place, hide once the mouse cursor moves out of it and so on.

<em>We can also minimize of maximize solution explorer window.</em>

8 0
3 years ago
Other questions:
  • There are a variety of common user interfaces. How would you decide which interface to use and on what should this decision be b
    11·1 answer
  • If you filmed a clip in 120fps, how many frames are in a seconds of video.
    13·1 answer
  • Why did latex replace wax?
    7·1 answer
  • Suppose you are given a bag containing n unbiased coins. You are told that n − 1 of these coins are normal, with heads on one si
    7·1 answer
  • Please help! would appreciate it very much!
    13·1 answer
  • A set of well-defined steps for performing a task or solving a problem is known as a(n):A) HierarchyB) AlgorithmC) Central Proce
    15·1 answer
  • Look at the following program and answer the question that follows it. 1 // This program displays my gross wages. 2 // I worked
    8·1 answer
  • Suppose you present a project and your supervisor comments that the graphics need to be a higher quality and suggests you replac
    9·2 answers
  • When the binary code is retrieved from ram and moved to the cpu, this stage is known as
    8·1 answer
  • Describe how you can use JavaScript to simulate the behavior of the placeholder attribute in older browsers
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!