What is wrong with the following code?  Identity at least 10 things wrong with this code.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

(python)

What is wrong with the following code?  Identity at least 10 things wrong with this code.  

  1. import random
  2. func generateSpeed(start, end):
  3.     ""Generate a random speed from start - end""
  4.     return int((end - start + 1) * random.random()) + start
  5. green == 0
  6. yellow = 0
  7. red = 0
  8. for counter range(20):
  9.     //Generate a random speed from 1 - 80
  10.     speed = generateSpeed(10, 80)
  11.     print("The speed is", speed, "MPH")
  12.     if speed < 0
  13.         continue:
  14.     #if speed >= 50, then classification = Green
  15.     if speed >= 50:
  16.         green + 1
  17.     #if speed < 50 and speed >= 25, then classification = Yellow
  18.     elif speed < 50 and speed >= 25:
  19.         yellow += 1
  20.     #if speed < 25, then classification = Red
  21.     else:
  22.         red += red
  23. else:
  24.     print("\nTRAFFIC SUMMARY:")
  25.     print("# Green observations (traffic moving faster than 50 m.p.h.):", green)
  26.     print("# Yellow observations (traffic moving between 25 and 50 m.p.h.):", yellow):
  27.     print("# Red observations (traffic moving slower than 25 m.p.h.): " + str(red))
 
Expert Solution
Step 1 Summary and CODE

I have corrected the code and explained using comments--

I have provided python code along with code screenshot and also provided output screenshot---------------

Code:

import random
# def keyword used to define the function
def generateSpeed(start, end):
    # comment must be starts with '#' rather than ""
    # Generate a random speed from start - end
    return int((end - start + 1) * random.random()) + start
# to store 0 in variable green we have to used assignment operator(=) ranther than equal operator (==)
green = 0
yellow = 0
red = 0
# in is used
for counter in  range(20):
    # comment must be starts with '#' rather than //
    # Generate a random speed from 1 - 80
    speed = generateSpeed(10, 80)
    print("The speed is", speed, "MPH")
    # every statement end with colon
    if speed < 0:
        # colon must not used with the statement
        continue
    #if speed >= 50, then classification = Green
    if speed >= 50:
        green + 1
    #if speed < 50 and speed >= 25, then classification = Yellow
    elif speed < 50 and speed >= 25:
        yellow += 1
    #if speed < 25, then classification = Red
    else:
        red += red
else:
    print("\nTRAFFIC SUMMARY:")
    print("# Green observations (traffic moving faster than 50 m.p.h.):", green)
    print("# Yellow observations (traffic moving between 25 and 50 m.p.h.):", yellow)
    print("# Red observations (traffic moving slower than 25 m.p.h.): " + str(red))

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY