mercredi 24 février 2021

Can someone correct for me with this code?(Vasya - Clerk)

The Problem: ''The new "Avengers" movie has just been released! There are a lot of people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 dollar bill. An "Avengers" ticket costs 25 dollars.

Vasya is currently working as a clerk. He wants to sell a ticket to every single person in this line.

Can Vasya sell a ticket to every person and give change if he initially has no money and sells the tickets strictly in the order people queue?

Return YES, if Vasya can sell a ticket to every person and give change with the bills he has at hand at that moment. Otherwise return NO.’’

I passed 19 test cases failed 1.

I had put the part return the failed test case in (** **)

def tickets(people):
a=0
b=0
c=0
for k in people:
    if k==25:
        a+=1
    elif k==50:
        b+=1
    elif k==100:
        c+=1
if c>=1:
    d=(c*100)-(b*50)-(a*25)
    if d==0:
        return 'YES'
    **elif d!=25:
        return 'NO'**
    elif d==25:
        return 'YES'
if c==0:
    e=(b*50)-(a*25)
    if b>a:
        return 'NO'
    elif e<=25 or a>b:
        return’YES'

enter image description here

enter image description here

Aucun commentaire:

Enregistrer un commentaire