128k views
3 votes
What is wrong with this python code? The syntax error is on the first line.

public class Box


{

private String myDate;

private String myContents;

private String myLocation;

public class Box(String date, String contents, String location)

{

myDate = date;

myContents = contents;

myLocation = location;

}

}

Box twentyThree = new Box("2016", "medical records", "storage closet");

Box zeroSeven = new Box(“2020”, “flu shot flyers", “receptionist’s office”);

Box twentyOne = new Box(“2018”, “lotion samples”, “waiting room”)

print (Box twentyThree = 1)

print (Box zeroSeven = 2)

print (Box twentyOne = 3)

User Tamikha
by
4.1k points

1 Answer

4 votes

class Box:

def __init__(self, date="", contents="", location=""):

self.d = date

self.c = contents

self.l = location

def displayBox(self):

if self.d != "":

print("The date is " + self.d)

else:

print("The date was not supplied")

if self.c != "":

print("The contents are " + self.c)

else:

print("The contents were not supplied")

if self.l != "":

print("The location is " + self.l)

else:

print("The location was not supplied")

obj = Box("2016", "medical records")

obj.displayBox()

This is how you would create a class in python. Your code seems to be part python part some other language. I hope this helps!

User Florian Bienefelt
by
4.0k points