Hackathon Python

Unix

 

1 & 2 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

MYSQL

 

1.

 

 

 

select itemname,itemprice from items

 

2.

 

select itemname from items where itemprice between 50 and 100

 

3.

 

select o.orderid,i.itemname,o.orderedqty from items i inner join orders o on o.itemid=i.itemid where orderedqty>10

 

4.

 

select itemid , count(*) from orders group by itemid having count(*)>1

 

 

5.

 

select itemname from items where itemid in ( select itemid from orders where orderedqty =(select max(orderedqty) from orders))

 

 

Python

 

1.

 

def countdivideby3and5(il):

    c=0

    for i in il:

        s=0

        if(i%3==0 and i%5==0):

            st=str(i)

            sl=list(st)

            for j in sl:

                s+=int(j)

            if(s%4!=0):

                   c+=1 

    return c

 

 

2.

 

 

class Question:

    def __init__(self,questionId,correctOption,score):

        self.questionId=questionId

        self.correctOption=correctOption

        self.status="Not Answered"

        self.score=score

class QuestionPaper:

    def __init__(self,paperId,questionList):

        self.paperId=paperId

        self.questionList=questionList

    def checkSolutions(self,d):

        for i,ii in d.items():

            for iii in self.questionList:

                if(i==iii.questionId):

                    if(ii==iii.correctOption):

                        iii.status="Correct"

                    else:

                        iii.status="Incorrect"

    def findResult(self):

        tsall=0

        tscore=0

        for i in self.questionList:

            if(i.status=="Correct"):

                tscore+=i.score

            elif(i.status=="Incorrect"):

                tscore-=(i.score*0.1)

                tscore=int(tscore)

            tsall+=i.score

        p=(tscore/tsall)*100

        if(p>80):

            return "Pass"

        else:

            return "Fail"

 

3.

 

class Product:

    def __init__(self,name,price,qty):

        self.name=name

        self.price=price 

        self.qty=qty 

class Store:

    def __init__(self,name,address,products):

        self.name=name 

        self.address=address

        self.products=products 

    def totalProductsPriceForCategory(self,cat):

        sum=0

        for i in self.products:

            na=i.name.split("-")

            na=na[0]

            if na in cat:

                if(i.qty!=0):

                    sum+=(i.price*i.qty)

        return sum

    def checkProductAvailability(self,lis):

        d={}

        for i in lis:

            k=0

            for j in self.products:

                if i==j.name:

                    if(j.qty>0):

                        k=1 

                    else:

                        k=2

            if(k==1):

               d[i]="Available"

            elif(k==2):

                d[i]="Out of stock"

            else:

                d[i]="Not Available"

        return d

    def calculateBill(self,pl):

        sum=0

        d=self.checkProductAvailability(pl)

        for i,j in d.items():

            if j=="Available":

                for k in self.products:

                    if(i==k.name):

                        sum+=k.price 

        return sum

 

©2018 by The real one. Proudly created with Wix.com