Calculate if we have won the lottery with python

In this chapter, I will create a method which will accept a list consists of sub-lists as the first input parameter and a number as the second parameter, there are two values in each sub-list, a string and a number. If any ASCII code of a character in that string matches the number in the sub-list, then we have a win in that sub-list. If the total wins in those sub-lists equal to or greater than the second input parameter of that method then you have won a lottery or else you lose.

Below is the method which we will create.

def bingo(ticket,win):
    count = 0 #the total wins
    for lottery in ticket:
        for char in lottery[0]:
            if(ord(char) == lottery[1]):
                count += 1
        return 'Winner!'
        return 'Loser!'

If we enter below parameters into that method…

print(bingo([['ABC', 65], ['HGR', 74], ['BYHT', 74]], 1))

Then we will win the lottery. Hope you like this short solution, I will start a new project on the next article so we will temporarily stop the one day one question series for a while and concentrate on our next python project.

Leave a Reply

Notify of