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]
3 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]3 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
Write a recursive, int -valued function, len, that accepts a string and returns the number of characters in the string .
vodka [1.7K]
Without knowing the language, it's pretty imposible to write it.  Once you start thinking recursively, it's not a difficult problem.

While you're recursing, pass the string without the first character.
The base case would be a null string which would return 0.
The unwind would just add one and return that.
7 0
3 years ago
Fill the validateForm function to check that the phone number contains a number (use the isNaN function) and that the user name
Wittaler [7]

The answer & explanation for this question is given in the attachment below.

8 0
3 years ago
What type of program would you use to create a personal budget?
Rina8888 [55]

Answer:

Using a spreadsheet would be the best program for creating a personal budget.

Explanation:

With a spreadsheet, you can enter formulas to add or subtract from your budget, plus you can create charts and graphs as well.

8 0
2 years ago
¿En qué situaciones puedo utilizar formato condicional?
pshichka [43]

Answer:

El formato condicional es una herramienta útil para identificar patrones o tendencias en una hoja de cálculo. Por ejemplo, una regla podría ser: si el valor es mayor que 5.000, que la celda sea amarilla. Así, podrás ver de un vistazo las celdas cuyo valor es superior a 5.000. Puedes usarlo para describir graficas cientificas o Datos matematicos.

Explanation:

El formato condicional facilita el proceso de resaltar celdas o rangos de celdas interesantes, destacar valores inusuales y ver datos empleando barras de datos, escalas de colores y conjuntos de iconos que se correspondan con las variaciones específicas de los datos.

6 0
3 years ago
Can someone help me with this please
alex41 [277]

Answer:

D

Explanation:

Filters and the Sort feature can be applied in any order. 

4 0
2 years ago
Other questions:
  • State College charges its departments for computer time usage on the campus mainframe. A student had access to the university co
    10·1 answer
  • Write a program to calculate how much to tip a waiter person based on the quality of service. The script file should ask for the
    12·1 answer
  • What is the wave speed of a wave that has a frequency of 100 Hz and a wavelength of 0.30m?
    5·1 answer
  • The gradual wearing away or breaking down of rocks by abrasion is a type of __________________ weathering.
    8·1 answer
  • Consider a Rational class designed to represent rational numbers as a pair of int's, along with methods reduce (to reduce the ra
    15·1 answer
  • Provide a class Letter for authoring a simple letter. In the constructor, supply the names of the sender and the recipient: def
    11·1 answer
  • How does computer science play a role in art?
    6·1 answer
  • Computers were originally developed to accomplish various tasks in relative isolation, very different from the collaboration and
    14·1 answer
  • Explain the relationship between one’s point of view and understanding spoken text
    13·1 answer
  • What was the name of the first computer, developed by charles babbage?.
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!