-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Bell Codo edited this page Aug 26, 2016
·
4 revisions
- To add mystery and magic to the plan begin in a new repo in github.
- Create a file
code_activities_we_like.lst - Brainstorm a list one item per line no spaces
codecombat
scratch
tynker
codeacademy
10fastfingers.com
typing.lk
typing.com/games
typingclub.com
- Commit the file.
- Navigate to codeskulptor.
- Select all the inner welcome code and delete it.
- Template out the steps to a new
activity_picker.pyapplication.
# import the magic random picker
# list of things to pick from
# find a way to pick something
# a way to tell the user what to do- Each of the stubbed out comments represents a logical aspect of the application.
- Now step through each section and implement the simplest possible example highlighting programming concepts along the way.
# import the magic random picker
# list of things to pick from
activities_to_do = []
# find a way to pick something
# a way to tell the user what to doIn programming the
=is not treated as equality like we are trained for in math, instead=means assignment. The mantra when readingsomething_on_the_left = 'a value'is: something_on_the_left gets 'a value'
- Start simple with an empty list.
- Run the program.
- Getting no output is the big 'it didn't fail' success!
# import the magic random picker
# list of things to pick from
activities_to_do = ['a','b','c']
# find a way to pick something
# a way to tell the user what to do- Add a few items to the list.
- Next print the list and enjoy some output.
# import the magic random picker
# list of things to pick from
activities_to_do = ['a','b','c']
# find a way to pick something
# a way to tell the user what to do
print activities_to_do- Plugging in the final piece of the equation.
- Assign
going_to_doan element from the list.
# import the magic random picker
# list of things to pick from
activities_to_do = ['a','b','c']
# find a way to pick something
going_to_do = activities_to_do[2]
# a way to tell the user what to do
print "The things we can do: " + str(activities_to_do)
print "The thing we are going to do: " + going_to_do- At this point the problem is multiple runs of the program yield activity
'c'. - To spice things up use
randomto pick any activity.
# import the magic random picker
import random
# list of things to pick from
activities_to_do = ['a','b','c']
# find a way to pick something
going_to_do = random.choice(activities_to_do)
# a way to tell the user what to do
print "The things we can do: " + str(activities_to_do)
print "The thing we are going to do: " + going_to_do- Ok buckle up!
- Reference link
- Next up,
import urllib2- GET request to copy the list from github raw.
-
str.split()to convert string of activities into a list.
- Navigate back to github and click on the 'code_activities_we_like.lst' file.
- Click on the 'raw' button.
- Copy the url out of the address bar.
- Paste the url into a new string and pass it to the library.
# import the magic random picker
import random, urllib2
# list of things to pick from
code_activities_we_like = 'https://raw.githubusercontent.com/bellcodo/potential-octo-chainsaw/15142655a8f4faa26d381ca00458fa4fcd8c2423/code_activities_we_like.lst'
activities_to_do = urllib2.urlopen(code_activities_we_like).read()
# find a way to pick something
going_to_do = random.choice(activities_to_do)
# a way to tell the user what to do
print "The things we can do: " + str(activities_to_do)
print "The thing we are going to do: " + going_to_do- Run it.
- Try and understand what the
print "The thing we are going to do:" + activities_to_doreturned. - Now split the result and assign it back to activities_to_do.
# import the magic random picker
import random, urllib2
# list of things to pick from
code_activities_we_like = 'https://raw.githubusercontent.com/bellcodo/potential-octo-chainsaw/15142655a8f4faa26d381ca00458fa4fcd8c2423/code_activities_we_like.lst'
activities_to_do = urllib2.urlopen(code_activities_we_like).read()
activities_to_do = activities_to_do.split()
# find a way to pick something
going_to_do = random.choice(activities_to_do)
# a way to tell the user what to do
print "The things we can do: " + str(activities_to_do)
print "The thing we are going to do: " + going_to_do- Running the application multiple times should result in different activities.
- Give it a try to decide what to do next.
Bellcodo is in association with Expedia Inc. and CoderDojo.
- Forum: Google Groups Bellcodo
- Email: bellcodo@gmail.com