susie’s lecture notes are in the presenter’s notes, below the slides disclaimer: susie may have...

30
Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there is any confusion, please email the lecture presenter.

Upload: nickolas-bryan

Post on 21-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Susie’s lecture notes are in the presenter’s notes, below the slidesDisclaimer: Susie may have made errors in transcription or understanding. If there is any confusion, please email the lecture presenter.

Page 2: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Psuedo Code

Page 3: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Real Code

Page 4: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Pseudo Code

• Pseudo = Fake• Code = Fancy computer stuff

• A way to organize your program before coding it

Page 5: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

General Guidelines

• Input• Output• Steps in between

• Not Language Specific• Only you need to understand it• Should not work

Page 6: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

ToolBox

• Variables (int, float, char, string)• Arrays• If• If-Else• While loop• For loop• Functions

Page 7: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

If - Else

If (True or False Statement)Run CodeRun More Code

ElseRun Other Code

Page 8: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Problem 1

• Matt keeps getting on your computer and running your code

• Write a program that asks for the users name• If its Matt tell him to get back to work• Input: User’s name• Output: Chiding Statement

Page 9: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Problem 1: Word Solution

• Load in a user name from the keyboard• Check if that name is matt• If it is matt, say something

Page 10: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Problem 1: Pseudo Code

User Name = userInput(stuff)If User Name is Matt

Print Boo Matt

Page 11: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Problem 1: Pseudo Code

User Name = userInput(stuff)If User Name is Matt

Print Angry StatementElse

Print You do You!

Page 12: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Class Problem 1

• Write a program that takes in a number from a user and tells them if it is Divisible by 11

• Input = User Number• Output = Printed statement on divisibility• Hint: Mod (%) gives the remainder• 5 Mod 2 = 1

Page 13: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Class Problem 1: Word Solution

• Load in a number from the user• See if that number is divisible by 11• If it is tell them• If it is not, tell them

Page 14: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Class Problem 1: Pseudo Code Solution

Number = userInput(stuff)If Number Mod 11 is 0

Print Affirmative StatementElse

Print Negative Statement

Page 15: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

While

While (True or False Statement)Do CodeDo More Code

Page 16: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Problem 2

• Write a program that takes in a number from a user and tells them if it is Divisible by 11

• But keep asking until the user enters the number 0

Page 17: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Problem 2: Pseudo Code

While(Number is not 0)Number = userInput(stuff)If Number Mod 11 is 0

Print Affirmative StatementElse

Print Negative Statement

Why will this not work?

Page 18: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Class Problem 2: Pseudo Code

Number = 1While(Number is not 0)

Number = userInput(stuff)If Number Mod 11 is 0

Print Affirmative StatementElse

Print Negative Statement

Page 19: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Array

• Cute = [‘Puppy’,’Kitten’,’Piglet’,’Tigger’]• 0 indexed: 0 1 2 3• 1 indexed: 1 2 3 4• 0 indexed: cute[1] = Kitten• 1 indexed: cute[1] = Puppy

Page 20: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

For Loop

• Two Main components:–Iterator Variable–Range

Page 21: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

For Loop

• For counter in 1 – 10–Print “pass” + counter

• For i = 1, i <= 10, i = i + 1–Print “pass” + counter

• For word in Words–Print word

Page 22: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Problem 3

• You are given a DNA Sequence and have to report how many times the Motif CAT appears

• Input = DNA Sequence (GATTACA), CAT• Output = CAT Count• Hint1: A string is really just as an array of

characters • [‘G’,’A’,’T’,’T’,’A’,’C’,’A’]• Hint2: you can take a slice out of an array– Array[2:4]

Page 23: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Problem 3: Word Solution

• Load DNA Sequence and CAT into variables• Set a motif counter to 0• Iterate through DNA sequence – Pull out sets of three letters and compare to CAT– If we find CAT increment the counter

• Report the final count

Page 24: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Visual Representation

•G A T T A C A

Page 25: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Problem 3: Pseudo Code

Motif = CATDNASeq = loadFile(InputDNA)CAT_Count = 0For i in DNASeq Range – 2

if(DNASeq i to DNASeq i+2 is CAT)CAT_Count + 1

Print CAT_Count

Page 26: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Class Problem 3

• You are given a DNA sequence and have to determine its GC content

• Input = DNA sequence (GATTACA)• Output = GC content• Hint: You can use a For loop to iterate through

the elements of an array

Page 27: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Class Problem 3: Pseudo Code

DNASeq = loadFile(InputDNA)GC_Count = 0For Letter in DNASeq

if Letter is G or CGC_Count + 1

DNALength = length(DNASeq)GC = GC_Count/DNALength X 100%Print GC

Page 28: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Real Code

Page 29: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Better Real Code

Page 30: Susie’s lecture notes are in the presenter’s notes, below the slides Disclaimer: Susie may have made errors in transcription or understanding. If there

Parting Lessons

• Inputs• Outputs• Toolbox• Take Your Time• Only you have to understand your pseudo

code