SlideShare a Scribd company logo
1 of 9
Defining Functions and
using Lists in EarSketch
D
A
Y
4
1MAGIC Presenter : Fatemeh Jamshidi. June 17-22 1
2/32
N
Functions
D
A
Y
4
MAGIC Presenter : Fatemeh Jamshidi. June 17-22 2
● fitMedia(), setTempo(), init(), and rang() are all
examples of functions.
● Functions allow a user to execute some
preexisting section of code without having to write it
over again.
● Functions also make code flow in a clearer way.
They reduce duplication of lines and small details
that get in the way of a clear understanding of a
script’s goals.
3/32
D
A
Y
4
MAGIC Presenter : Fatemeh Jamshidi. June 17-22 3
Let’s take a look at how a function is defined:
Functions
● When we define a function, we use to let python know that there is a
new function being defined.
● Then we name the function, and define what kinds of parameters it expects.
● These parameters, defined through variables, allow the function to accept
arguments.
● When is called, the files are inserted into the first two
tracks to be played simultaneously, just like the original code. It also takes a
measure, meaning that you can pass it a number to make it play at particular
times.
4/32
Assignment
D
A
Y
4
MAGIC Presenter : Fatemeh Jamshidi. June 17-22 4
How would you clean up this code?
1/5/32
Data Structure
D
A
Y
4
MAGIC Presenter : Fatemeh Jamshidi. June 17-22 5
● In order to make programming easier, computer scientists have
developed data structures.
● Data structures are used to hold information of various kinds and
make manipulating that data easier. Without data structures,
storing and manipulating data can quickly become complicated
and chaotic.
For example, imagine trying to organize books without a
bookshelf.
6/32
Lists
D
A
Y
4
MAGIC Presenter : Fatemeh Jamshidi. June 17-22 6
● One very useful data structure that we’ll frequently use is called a
list.
● Every item in the list is numbered as an index.
● A list is named just like a variable is, but needs brackets around
the items that are being placed in it. These items are separated by a
comma as follows:
beats = [HIP_HOP_GUITAR1_2M, HIP_HOP_GUITAR2_4M,
HIP_HOP_GUITAR3_4M, HIP_HOP_GUITAR4_4M]
7/32
Lists
D
A
Y
4
MAGIC Presenter : Fatemeh Jamshidi. June 17-22 7
Once the above code is run, our bookshelf list would look
something like this:
8/32
Lists and Randomness
D
A
Y
4
MAGIC Presenter : Fatemeh Jamshidi. June 17-22 8
Another way to use lists is with randomness. Python’s
function can be used to select from a list at a random index.
Here’s the 12 measure fill example from before with random
drums:
9/32
Assignment
D
A
Y
4
MAGIC Presenter : Fatemeh Jamshidi. June 17-22 9
Make a list called myMusic that contains at
least 4 samples that you think will work well
together. Use for loops and functions (as
needed) use the list to create a 12 measure
composition.

More Related Content

What's hot (16)

Basics of data structure
Basics of data structureBasics of data structure
Basics of data structure
 
Data structures
Data structuresData structures
Data structures
 
What is Non-primitive data type?
What is Non-primitive data type?What is Non-primitive data type?
What is Non-primitive data type?
 
Python pandas liberary
Python pandas liberaryPython pandas liberary
Python pandas liberary
 
Data struters
Data strutersData struters
Data struters
 
Tutorial olap4j
Tutorial olap4jTutorial olap4j
Tutorial olap4j
 
Data types
Data typesData types
Data types
 
Flat Filer Presentation
Flat Filer PresentationFlat Filer Presentation
Flat Filer Presentation
 
C++
C++C++
C++
 
Stack
StackStack
Stack
 
Data structure
Data structureData structure
Data structure
 
Data Structure # vpmp polytechnic
Data Structure # vpmp polytechnicData Structure # vpmp polytechnic
Data Structure # vpmp polytechnic
 
Introduction of structure
Introduction of structureIntroduction of structure
Introduction of structure
 
Elementary data organisation
Elementary data organisationElementary data organisation
Elementary data organisation
 
Stata 101
Stata 101Stata 101
Stata 101
 
Making art (and more!) with metadata
Making art (and more!) with metadataMaking art (and more!) with metadata
Making art (and more!) with metadata
 

Similar to Day 4( magic camp)

Physical Plans in Spark SQL
Physical Plans in Spark SQLPhysical Plans in Spark SQL
Physical Plans in Spark SQLDatabricks
 
chapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptxchapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptxAmrutaNavale2
 
cis5-204-Project-ch11c - Evan, Le, Mata.pdf
cis5-204-Project-ch11c - Evan, Le, Mata.pdfcis5-204-Project-ch11c - Evan, Le, Mata.pdf
cis5-204-Project-ch11c - Evan, Le, Mata.pdfMinhLe595264
 
Blueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBlueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBhalaji Nagarajan
 
Hadoop and cassandra
Hadoop and cassandraHadoop and cassandra
Hadoop and cassandraChristina Yu
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptxKarthickT28
 
Graph Analytics with ArangoDB
Graph Analytics with ArangoDBGraph Analytics with ArangoDB
Graph Analytics with ArangoDBArangoDB Database
 
Mapreduce Algorithms
Mapreduce AlgorithmsMapreduce Algorithms
Mapreduce AlgorithmsAmund Tveit
 
R programming for data science
R programming for data scienceR programming for data science
R programming for data scienceSovello Hildebrand
 
Introduction to Data structure and algorithm.pptx
Introduction to Data structure and algorithm.pptxIntroduction to Data structure and algorithm.pptx
Introduction to Data structure and algorithm.pptxline24arts
 
Notes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testsNotes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testspriyanshukumar97908
 
Introduction to Python programming Language
Introduction to Python programming LanguageIntroduction to Python programming Language
Introduction to Python programming LanguageMansiSuthar3
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdNimmi Weeraddana
 
CS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfCS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfraji175286
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structureZaid Shabbir
 

Similar to Day 4( magic camp) (20)

Physical Plans in Spark SQL
Physical Plans in Spark SQLPhysical Plans in Spark SQL
Physical Plans in Spark SQL
 
chapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptxchapter 1 Introduction to Ds and Algorithm Anyasis.pptx
chapter 1 Introduction to Ds and Algorithm Anyasis.pptx
 
CIS 5 Project.pdf
CIS 5 Project.pdfCIS 5 Project.pdf
CIS 5 Project.pdf
 
cis5-204-Project-ch11c - Evan, Le, Mata.pdf
cis5-204-Project-ch11c - Evan, Le, Mata.pdfcis5-204-Project-ch11c - Evan, Le, Mata.pdf
cis5-204-Project-ch11c - Evan, Le, Mata.pdf
 
Blueprints: Introduction to Python programming
Blueprints: Introduction to Python programmingBlueprints: Introduction to Python programming
Blueprints: Introduction to Python programming
 
Hadoop and cassandra
Hadoop and cassandraHadoop and cassandra
Hadoop and cassandra
 
Functional Programming.pptx
Functional Programming.pptxFunctional Programming.pptx
Functional Programming.pptx
 
Graph Analytics with ArangoDB
Graph Analytics with ArangoDBGraph Analytics with ArangoDB
Graph Analytics with ArangoDB
 
Classification of DS.pptx
Classification of DS.pptxClassification of DS.pptx
Classification of DS.pptx
 
Mapreduce Algorithms
Mapreduce AlgorithmsMapreduce Algorithms
Mapreduce Algorithms
 
R programming for data science
R programming for data scienceR programming for data science
R programming for data science
 
Introduction to Data structure and algorithm.pptx
Introduction to Data structure and algorithm.pptxIntroduction to Data structure and algorithm.pptx
Introduction to Data structure and algorithm.pptx
 
Notes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testsNotes of bca Question paper for exams and tests
Notes of bca Question paper for exams and tests
 
Data structure
Data structureData structure
Data structure
 
Introduction to Python programming Language
Introduction to Python programming LanguageIntroduction to Python programming Language
Introduction to Python programming Language
 
Data structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pdData structures and algorithms short note (version 14).pd
Data structures and algorithms short note (version 14).pd
 
Data structure
 Data structure Data structure
Data structure
 
CS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfCS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdf
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Ch-8.pdf
Ch-8.pdfCh-8.pdf
Ch-8.pdf
 

More from FatemehJamshidi5

More from FatemehJamshidi5 (7)

Presentation
PresentationPresentation
Presentation
 
Day 5( magic camp)
Day 5( magic camp)Day 5( magic camp)
Day 5( magic camp)
 
Day 3( magic camp)
Day 3( magic camp)Day 3( magic camp)
Day 3( magic camp)
 
Ear sketch(presentation)
Ear sketch(presentation) Ear sketch(presentation)
Ear sketch(presentation)
 
Day 2( magic camp)
Day 2( magic camp)Day 2( magic camp)
Day 2( magic camp)
 
Day 2( magic camp)1
Day 2( magic camp)1Day 2( magic camp)1
Day 2( magic camp)1
 
Day 1( magic camp)(1)
Day 1( magic camp)(1)Day 1( magic camp)(1)
Day 1( magic camp)(1)
 

Recently uploaded

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 

Recently uploaded (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

Day 4( magic camp)

  • 1. Defining Functions and using Lists in EarSketch D A Y 4 1MAGIC Presenter : Fatemeh Jamshidi. June 17-22 1
  • 2. 2/32 N Functions D A Y 4 MAGIC Presenter : Fatemeh Jamshidi. June 17-22 2 ● fitMedia(), setTempo(), init(), and rang() are all examples of functions. ● Functions allow a user to execute some preexisting section of code without having to write it over again. ● Functions also make code flow in a clearer way. They reduce duplication of lines and small details that get in the way of a clear understanding of a script’s goals.
  • 3. 3/32 D A Y 4 MAGIC Presenter : Fatemeh Jamshidi. June 17-22 3 Let’s take a look at how a function is defined: Functions ● When we define a function, we use to let python know that there is a new function being defined. ● Then we name the function, and define what kinds of parameters it expects. ● These parameters, defined through variables, allow the function to accept arguments. ● When is called, the files are inserted into the first two tracks to be played simultaneously, just like the original code. It also takes a measure, meaning that you can pass it a number to make it play at particular times.
  • 4. 4/32 Assignment D A Y 4 MAGIC Presenter : Fatemeh Jamshidi. June 17-22 4 How would you clean up this code?
  • 5. 1/5/32 Data Structure D A Y 4 MAGIC Presenter : Fatemeh Jamshidi. June 17-22 5 ● In order to make programming easier, computer scientists have developed data structures. ● Data structures are used to hold information of various kinds and make manipulating that data easier. Without data structures, storing and manipulating data can quickly become complicated and chaotic. For example, imagine trying to organize books without a bookshelf.
  • 6. 6/32 Lists D A Y 4 MAGIC Presenter : Fatemeh Jamshidi. June 17-22 6 ● One very useful data structure that we’ll frequently use is called a list. ● Every item in the list is numbered as an index. ● A list is named just like a variable is, but needs brackets around the items that are being placed in it. These items are separated by a comma as follows: beats = [HIP_HOP_GUITAR1_2M, HIP_HOP_GUITAR2_4M, HIP_HOP_GUITAR3_4M, HIP_HOP_GUITAR4_4M]
  • 7. 7/32 Lists D A Y 4 MAGIC Presenter : Fatemeh Jamshidi. June 17-22 7 Once the above code is run, our bookshelf list would look something like this:
  • 8. 8/32 Lists and Randomness D A Y 4 MAGIC Presenter : Fatemeh Jamshidi. June 17-22 8 Another way to use lists is with randomness. Python’s function can be used to select from a list at a random index. Here’s the 12 measure fill example from before with random drums:
  • 9. 9/32 Assignment D A Y 4 MAGIC Presenter : Fatemeh Jamshidi. June 17-22 9 Make a list called myMusic that contains at least 4 samples that you think will work well together. Use for loops and functions (as needed) use the list to create a 12 measure composition.