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
you are a bank loan officer. carter has to come into your office and applied for a loan for a car.you ran his credit report, and
elena-14-01-66 [18.8K]

Answer:

Carter score falls within the range of scores, from 300 to 579, considered Very Poor. Score is significantly below the average credit score.

Explanation:

5 0
3 years ago
How to access Tor Browser on Android which is not rooted?
Mekhanik [1.2K]
An app you can look up on Google chrome called Aptoide has it on there for you to install.
7 0
3 years ago
Complete the sentence. <br><br> ____ Is the study and use of very small technology units
kondor19780726 [428]

Answer:

nanotechnology

Explanation:

I just took the test

3 0
3 years ago
TRUE OR FALSE!!!!!
KatRina [158]

Answer:

True

Explanation:

Using CCleaner, it's revealed that there are trackers within "secure" websites/apps such as Google and Tiktok. The manufacturer(s) of these websites/apps can share your information with whoever they're working with. Since people often look past the terms and conditions when installing an app and or program, they don't see that companies can easily retrieve all of your data within a couple clicks.

6 0
3 years ago
What is the name of an instruction that interrupts a program being executed and requests a service from the operating system
tresset_1 [31]
“Interrupt” is what I think the answer is
7 0
2 years ago
Other questions:
  • A ________ is a set of programs that manipulate the data within a database.
    12·1 answer
  • Which button is used to open the Start menu in Windows Vista?
    14·1 answer
  • How would I CAST this variable to a STRING?<br> teeth = 32
    9·1 answer
  • Research shows that a passive close to a cover letter leads to more interviews. Please select the best answer from the choices p
    8·2 answers
  • To remove an embedded chart, you should _____ it and press the DELETE key. (Points : 2) move drag hide click
    15·1 answer
  • It’s been six months since the disk crash at CSM Tech Publishing, and the owner is breathing a little easier because you install
    7·1 answer
  • Individual internet users connect to isps through a(n ________.
    11·1 answer
  • Which statement describes what the Conditional Formatting option in Excel 2016 allows users to do?
    15·2 answers
  • Which command os used to find a particular word in a document ?<br>​
    9·2 answers
  • Most of the internal operations in a computer use hexagonal numbering true or false
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!