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
The following code accomplishes which of the tasks written below? Assume list is an int array that stores positive int values on
worty [1.4K]

Answer:

it stores the largest value in list (the maximum) in foo

Explanation:

Initially foo is assigned as the first element of the list

Inside the loop, every element in the list will be compared with foo, starting from the second element. If an element is greater than foo, the new value of the foo will be that element. At the end of the loop, foo will be equal to the largest element in the list.

5 0
2 years ago
I need help, who is a great phone pin lock screen cracker?
svlad2 [7]

Answer:

738159

now it's depend on you.

4 0
2 years ago
Design the program in the following way:
natali 33 [55]

Answer:

d = {}

while True:

   name = input("Enter the name of the boat (Press Enter or q to stop): ")

   if name == "" or name == "q":

       break

   time = int(input("Enter the time (in seconds): "))

   d[name] = time

winner_name = min(d, key=d.get)

winner_time = min(d.values())

average_time = sum(d.values()) / len(d.values())

slowest_boat = max(d, key=d.get)

slowest_time = max(d.values())

print(f"Winner name: {winner_name} and its time: {winner_time}")

print(f"Average time: {average_time}")

print(f"Slowest boat: {slowest_boat} and its time: {slowest_time}")

Explanation:

*The code is in Python.

Create an empty map(dictionary) to hold the values

Create a while loop. Inside the loop:

Ask the user to enter the name of the boat. Check if the user presses Enter or q, using if and break

Ask the user to enter the time

Insert these values as key-value pair to the map

When the loop is done:

Find the winner_name, the min() function finds the minimum value in a list. In this case, the key=d.get creates a list of the values in the map. The min(d, key=d.get) returns the key of the minimum value

Find the winner_time, min(d.values()) returns the minimum time in our map

Find the average time, the sum() function, returns the sum of the values in a list. In this case, sums all the values in the map. The len() function finds the count of the values. If we divide the sum of times entered by the count of the times entered, we get the average time

Find the slowest_time, the max() function returns the max of the value in a list. In this case, the maximum value is the slowest time

Print the results

5 0
2 years ago
List seven basic internet components found in a computer tower
Alexxandr [17]
A Mouse and a Keyboard are examples of eternal input devices. The monitor, printer, speaker and Fash drive are all external output devices. Seven basic internal components in a computer tower are the power supply unit, central processing unit, hard disk drive, RAM modules, motherboard, video card and a sound card.
8 0
2 years ago
Read 2 more answers
Which two protocols manage neighbor discovery processes on ipv4 networks?.
serious [3.7K]

Answer:

Which two protocols manage neighbor discovery processes on IPv4 networks? TCP and UDP BGP and OSPF ICMP and ARP IPv4 and IPv6

Key Links. Pricing.

Subjects. Medical & Nursing.

Company. About Us.

Find Us.

Explanation:

6 0
2 years ago
Other questions:
  • What is the next series of dragon ball super
    6·2 answers
  • Janelle is shopping for jeans from Express. She clicks on a style she likes. The site quickly presents her with a close-up view
    5·1 answer
  • TRUE OR FALSE: Individuals involved in surveillance prior to a terrorist attack are always well-trained and equipped.
    13·1 answer
  • The negotiation by the transport layer at the sender with the transport layer at the receiver to determine what size packets sho
    14·1 answer
  • Which is most harmful computer virus define​
    15·1 answer
  • for what reason do some security professionals consider insiders more dangerous than outside intruders?
    8·1 answer
  • To communicate with an expansion card, one part of the ____ bus runs between RAM and the processor; the other part runs between
    13·1 answer
  • The domain name service (dns is a distributed database that allows users to communicate with each other computers by:
    7·1 answer
  • Write a program that administers and grades quizzes. A quiz consists of questions. There are four types of questions: text quest
    13·1 answer
  • Help me pls...
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!