I am very new to python and am currently taking a class in it at my university. I am stuck on a program that my professor wants us to write. I think that I have most of what he wants working except for correctly passing the variables to the method getClass in the class Traffic. Here is the given assignment:
Step 4:
Steps:
- Modify the class called
Trafficthat will have four private attributes: throughput, delay, jitter, loss.- Modify the method called
getClasswithin theTrafficclass, that will classify traffic as below:
- Best effort: throughput < 5, delay between 8 and 10
or
Throughput between 5 and 10, delay > 8- Controlled load: throughput between 5 and 10 , delay <= 8
or
Throughput >=10, delay >= 5- Guaranteed: throughput >=10, delay < 5
Write a program called
testTrafficClassto test the traffic class. The program will have amain()function that will initialize the four attributes of class Traffic, and print the traffic class. It will then prompt the user to change the attributes, and will print traffic class based on the new values.
Here is the code I have so far:
def Main():
def __init__(self, throughput = 0, delay = 0, jitter = 0, loss = 0):
self.__throughput = throughput
self.__delay = delay
self.__jitter = jitter
self.__loss = loss
throughput = eval(input("Enter Throughput: "))
delay = eval(input("Enter Delay: "))
jitter = eval(input("Enter Jitter: "))
loss = eval(input("Enter Loss: "))
Traffic.getClass(self, throughput, delay)
class Traffic:
def getClass(self, throughput, delay):
if (throughput<5) and (delay <= 10) and (8<=delay):
print("Best Effort")
if (5<=throughput) and (throughput<=10) and (delay>8):
print ("Best Effort")
if (5<=throughput) and (throughput<=10) and (delay<=8):
print ("Controlled load")
if (throughput >=10) and (delay >=5):
print ("Controlled load")
if (throughput >=10) and (delay <5):
print ("Guaranteed")
Main()
I'm sure this isn't the best or most elegant code there is since I am very new to Python. If someone could get me on the right track that would be great. I keep getting errors when I run it.
__init__method really inmain? It seems like it should be in theTrafficclass definition.