Friday, 21 March 2014

Sahil's question finished

def main():
    tip=0
    tipcount=0
    price=int(input("How much was your meal?"))
    if price > 200:
        tip = 0.11 * price
    elif price > 99 and price < 199:
        tip = 0.10 * price
    elif price > 49 and price < 100:
        tip = 0.08 * price
    elif price < 50:
        tip = 0.065 * price
    tipprice = tip * price
    print("Your tip is", tip)
    print("Pay up!!")

Thursday, 20 March 2014

Abi's code finished

def main():
    best=0
    worst=100
    total=0
    count=1
    while count<4:
        swimtime=int(input("How fast is your swim time?"))
        if swimtime>best:
            best=swimtime
        elif swimtime<worst:
            worst=swimtime
        total=total+swimtime
        print(best, worst)
        count=count+1
    print(best, worst)
    print("The average is ",total/count)

My question


Write an algorithm in the form of a flowchart that:

·         Inputs the top speeds of a number of cars

·         Outputs the fastest top speed and the slowest top speed of the cars entered

·         Outputs the average speed of all the top speeds entered

 

 

Program it in python

Monday, 3 March 2014

Logic Gates in Python

def AndGate():
    print("Welcome to the And gate simulator")
    a = int(input("Please enter 1 or 0"))
    b = int(input("Please enter 1 or 0"))
    if a==1 and b==1:
        c=1
    elif a==1 and b==0:
        c=0
    elif a==0 and b==1:
        c=0
    elif a==0 and b==0:
        c=0
    print(c)
def OrGate():
    print("Welcome to the Or gate simulator")
    a = int(input("Please enter 1 or 0"))
    b = int(input("Please enter 1 or 0"))
    if a==1 and b==1:
        c=1
    if a==1 and b==0:
        c=1
    if a==0 and b==1:
        c=1
    if a==0 and b==0:
        c=0
    print(c)
def NotGate():
    print("Welcome to the Not gate simulator")
    a = int(input("Please enter 1 or 0"))
    if a==1:
        c=0
    if a==0:
        c=1
    print(c)
   
def NandGate():
    print("Welcome to the Nand gate simulator")
    a = int(input("Please enter 1 or 0"))
    b = int(input("Please enter 1 or 0"))
    if a==1 and b==1:
        c=0
    elif a==1 and b==0:
        c=1
    elif a==0 and b==1:
        c=1
    elif a==0 and b==0:
        c=1
    print(c)
def NorGate():
    print("Welcome to Nor gate simulator")
    a = int(input("Please enter 1 or 0"))
    b = int(input("Please enter 1 or 0"))
    if a==1 and b==1:
        c=0
    if a==1 and b==0:
        c=0
    if a==0 and b==1:
        c=0
    if a==0 and b==0:
        c=1
    print(c)
def XorGate():
    print("Welcome to Xor gate simulator")
    a = int(input("Please enter 1 or 0"))
    b = int(input("Please enter 1 or 0"))
    if a==1 and b==1:
        c=0
    elif a==1 and b==0:
        c=1
    elif a==0 and b==1:
        c=1
    elif a==0 and b==0:
        c=0
    print(c)