Tuesday, October 16, 2018

Strings, Lists, Files

String stuff

#strings, Lists, files
def main():
    mystring='This has already been a long morning.'
    print ('there are',len(mystring),'characters')
    print ('the 12th character is',mystring[12])
    for c in range(len(mystring)):
        print(mystring[c])
    midstring=mystring[9:17]
    print (midstring)
    wordlist=mystring.split()
    print(wordlist)
    print(wordlist[5])
    for w in range(len(wordlist)):
        print(wordlist[w])
    mystring=mystring.upper()
    print(mystring)
    mystring=mystring.lower()
    print(mystring)
    mystring=mystring.title()
    print(mystring)
    print (ord('a'))
    print (ord('A'))
    print(chr(97))
    print(chr(475))
    daylist='sun,mon,tue,wed,thurs,fri,sat'
    days=daylist.split(",")
    print(days)


main()

ListExamples

#Lists
def main():
    numbers=[1,37,4,4,2,1,9,10]
    sum=0
    for i in range(0,len(numbers)):
        sum += numbers[i]
    average=sum/len(numbers)
    print('the total is', sum, '\n' + 'the average is', average)

    mylist=[]
    for i in range(5):
       word=input("Enter a word: ")
        mylist.append(word)
    print(mylist)

    testgrade=[]
    num = int(input("How many grades: "))
    total=0
    
    for g in range(num):
        grade=float(input("Enter grade: "))
        testgrade.append(grade)
    
    print(testgrade)
    for g in range(0,len(testgrade)):
        total += testgrade[g]
    avg=total/len(testgrade)
    print("the average grade is", avg )

main()

FileExamples.py

#write and read a file
def main():
    outfile=open("C:\\temp\\outfile.txt", "w")
    print("this is my first sentence", file=outfile)
    print("this is my second sentence", file =outfile)
    outfile.close()

    infile=open('C:\\temp\\outfile.txt','r')
    for line in infile:
        print(line)
    infile.close()

main()

Monday, October 15, 2018

bit of SQL

Create Table Sale
(
  SaleID int identity(1,1) primary key,
  SaleDate DateTime default Current_timestamp,
  CustomerID int Foreign Key 
            references Customer(CustomerID)
);

Insert into Product(ProductName, ProductPrice)
Values('Plain donut',1.50),
('Cheese Danish', 3.25)

Select * from Product

Create Table SQL

Create Table Sale
(
   SaleID int identity(1,1) primary key,
   SaleDate Datetime default current_timestamp,
   CustomerID int Foreign key
       references Customer(CustomerID)
   --price decimal(6,2) not null
)

Thursday, October 11, 2018

Peer 4 exercise

#import graphics module
from graphics import *

#draw two circles in a ven diagram
def main():
    win=GraphWin("Ven",300,200)
    center=Point(100,100)
    radius=60
    circ=Circle(center, radius)
    circ.draw(win)
    center2=Point(200, 100)
    circ2=Circle(center2,radius)
    circ2.draw(win)
    win.getKey()

main()

Tuesday, October 9, 2018

graphics python

Vans.py

# determine the number of vans needed

def main():
    people=int(input("Enter the number of passengers: "))
    vanLoad=8
    numOfVans=people//vanLoad
    leftOver=people % vanLoad #modulus
    print("number of vans: ", numOfVans)
    print("Left over people", leftOver)
    #print ("If any people are left over order another van")
    if leftOver > 0:
        numOfVans = numOfVans + 1
    
    print ("you will need ", numOfVans, "vans")


main()

graphicsstuff.py

#import graphics
from graphics import *

def main():
    win =GraphWin("First graphics", 400,500)
    rec=Rectangle(Point(100,100), Point(300,300))
    rec.setFill('Blue')
    rec.draw(win)
    point=Point(200,200)
    circ=Circle(point,100)
    circ.setFill('Red')
    circ.draw(win)
    line = Line(Point(100,280), Point(280,280))
    line.setWidth(10)
    line.draw(win)
    win.getKey()

main()

ConvertForm.py

from graphics import *

def main():
    win=GraphWin("Celsius Converter", 400, 300)
    win.setCoords(0.0,0.0,3.0,4.0)
    Text(Point(1,3), "Celsius Temperature: ").draw(win)
    Text(Point(1,1), "Fahrenheit temperature: ").draw(win)
    inputText=Entry(Point(2.25,3),5)
    inputText.setText("0.0")
    inputText.draw(win)
    outputText=Text(Point(2.25,1), "")
    outputText.draw(win)
    button=Text(Point(1.5,2.0),"convert it")
    button.draw(win)
    Rectangle(Point(1,1.5), Point(2,2.5)).draw(win)

    win.getMouse()

    celsius = float(inputText.getText())
    fahrenheit=9.0/5.0 * celsius + 32

    outputText.setText(round(fahrenheit, 2))
    button.setText("Quit")

    
    win.getMouse()
    win.close()
main()

Thursday, October 4, 2018

Math python

CountChange.py

#program counts change
#int, float
import math

def main():
    print("Change Counter")
    print()
    print("please enter the count of coin type ")
    quarters = int(input ("Quarters: "))
    dimes=int(input("Dimes: ") )
    nickles=int(input("Nickles: "))
    pennies=int(input("Pennies: "))
    total = quarters * .25 + dimes * .10 + nickles * .05 + pennies * .01
    print()
    print("The total value is:  ", round(total,2))

main()

Here are are math excercises

import math

root = math.sqrt(144)
print(root)

#Integer Division
quotient = 12 // 7
remainder = 12 % 7
print("the quotient is ", quotient, "the remainder is ", remainder)
#float division
result = 12 / 7
print (result)
cube = 4 ** 3
print (cube)

Wednesday, October 3, 2018

Normalization. Afternoon

First Normal Form

all the data in an attribute must be of the same kind (logical, data type)

No lists or arrays

Track1, track2, track3. . .13

"track1,track2,track3..."

Second Normal Form

Assumes 1NF

Remove Structural dependencies, subsets, Groups of attributes that refer to each other but not to the topic (key) of the entity

Third Normal Form

Assumes 2NF

Remove transistive dependencies

One attribute that refers to another attribute

The Gist

Every Entity should be about one thing

Every attribute in the entity should describe that entity

Here is our final ERD