Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 49 additions & 18 deletions 1-python-question.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,59 @@
}




def OutputFormat():
output={
"successfulApplicants": [],
"bannedApplicants": [],
"totalCost": 0,
"tickets": [],
}
return output

def Banned(app, output):
if app in bannedVisitors:
output[Banned].append(app)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you referring to the Banned function here?

return True
return False

def Ticket(app, output):
ticket={
"name": app,
"membershipStatus": memberStatus.get(app, False),
"price": 3.5 if memberStatus.get(app, False) else 5
}
output['tickets'].append(ticket)
output['successfulApplicants'].append(app)
output['totalCost']+=ticket['price']


def processRequest(request):
# Your code here
return
if len(request["applicants"]) == 0:
return{"Error":"No Applicants"}
output = OutputFormat
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you referring to the function or the execution of the function

for app in request["applicants"]:
if Banned(app, output):
continue
Ticket(app, output)

return output
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning here causes everything belwo to not run


print(processRequest(request))

# {
# successfulApplicants:
# bannedApplicatns:
# totalCost:
# tickets: [
# {
# "name": ,
# "membershipStatus": ,
# "price":
# }, ....
# ]
#
# }

try:
if len(request["applicants"])==0:
raise Exception({"Error": "No Applicants"})
output = OutputFormat()
for app in request["applicants"]:
if Banned(app, output):
continue
Ticket(app, output)
return output
except Exception as e:
return "Oops something went wrong"


# OR

# {"error": "No applicants"}
print(processRequest(request))