Repository navigation
Intro-Python
Public
forked from
bloominstituteoftechnology/Intro-Python-I
About
Introduction to Python basics
Resources
Readme
Activity
Custom properties
Stars
0 stars
Watchers
0 watching
Forks
0 forks
Report repository
Branches
Tags
Go to Branches page Go to Tags page
Latest commit
History
23 Commits
View commit history for this file.
Folders and files
Repository files navigation
Intro to Python
Goals
It's time to learn a new language! Python!
Python is a popular, easy-to-use programming language that has significant traction in the field.
Remember the goal is learning to learn , so keep track of what works for you and what doesn't as you go through the process of exploring Python.
Techniques for learning new languages
-
Try to relate things you already know in another language (e.g. what an array is) to the corresponding things in Python (e.g. a list ) and how to use them.
-
Write a bunch of "toy programs" that demonstrate different key features of the language
-
Explore the standard library that's available for the language. Skim it briefly for now--the idea isn't to memorize everything but to file away generally what functionality is available.
-
Write a more substantial toy program that uses a variety of the features.
Again, keep track of what works for you. Try different things to see what works
best for learning new languages.
Resources
Getting started
-
Make sure you have Python 3 and pipenv installed.
-
Go to the directory with the Pipfile and run
pipenv install
-
After the install completes, run
pipenv shell
This will get you into the virtual environment. At this point, you should be
able to run Python 3 by just running python:
$ python --version
Python 3.6.5
You can exit the virtual environment by typing exit.
Days 1 and 2
Goals
- Learn the basic syntax and structure of Python
Summary
- Implement a number of tiny Python programs that demonstrate Python syntax.
Instructions
Take a look in the src/ directory.
NOTE: adv/ is for Day 2, so ignore it for today.
Suggested order for implementing the toy programs:
hello -- Hello world
bignum -- Print some big numbers
datatypes -- Experiment with type conversion
modules -- Learn to import from modules
printf -- Formatted print output
lists -- Python's version of arrays
tuples -- Immutable lists typically for heterogenous data
slice -- Accessing parts of lists
comp -- List comprehensions
dicts -- Dictionaries
func -- Functions
args -- Arguments and Keyword Arguments
scope -- Global, Local, and Non-Local scope
fileio -- Read and write from files
cal -- Experiment with module imports
obj -- Classes and objects
Days 3 and 4
Goals
- Solidify the Python basics by implementing a simple text adventure game
Summary
- Add classes for rooms and the player
- Add a simple parser that reads user input and performs actions
- Add items to the game that the user can carry around
- Make rooms able to hold multiple items
- Make the player able to carry multiple items
- Add two-word commands to the parser
- Add the
get and drop commands to the parser
Instructions
This is in src/adv/. Check it out!
-
Put the Room class in room.py based on what you see in adv.py.
-
Put the Player class in player.py.
-
Create a file called item.py and add an Item class in there.
-
Add the ability to add items to rooms.
-
The Room class should be extended with a list that holds the Items
that are currently in that room.
-
Add functionality to the main loop that prints out all the items that are
visible to the player when they are in that room.
-
Add capability to add Items to the player's inventory. The inventory can
also be a list of items "in" the player, similar to how Items can be in a
Room.
-
Add a new type of sentence the parser can understand: two words.
-
Until now, the parser could just understand one sentence form:
verb
such as "n" or "q".
-
But now we want to add the form:
verb object
such as "take coins" or "drop sword".
-
Split the entered command and see if it has 1 or 2 words in it to determine
if it's the first or second form.
-
Implement support for the verb get followed by an Item name. This will be
used to pick up Items.
-
Implement support for the verb drop followed by an Item name. This is the
opposite of get/take.
-
Add the i and inventory commands that both show a list of items currently
carried by the player.
Stretch Goals
In arbitrary order:
-
Add more rooms
-
Add scoring
-
Subclass items into treasures
-
Add a subclass to Item called LightSource.
-
During world creation, add a lamp LightSource to a convenient Room.
-
Override on_drop in LightSource that tells the player "It's not wise to
drop your source of light!" if the player drops it. (But still lets them drop
it.)
-
Add an attribute to Room called is_light that is True if the Room is
naturally illuminated, or False if a LightSource is required to see what
is in the room.
-
Modify the main loop to test if there is light in the Room (i.e. if
is_light is True or there is a LightSource item in the Room's
contents or if there is a LightSource item in the Player's contents).
-
If there is light in the room, display name, description, and contents as
normal.
-
If there isn't, print out "It's pitch black!" instead.
-
Hint: isinstance might help you figure out if there's a LightSource
among all the nearby Items.
-
Modify the get/take code to print "Good luck finding that in the dark!" if
the user tries to pick up an Item in the dark.
-
Add methods to notify items when they are picked up or dropped
-
Add light and darkness to the game
-
Add more items to the game.
-
Add a way to win.
-
Add more to the parser.
-
Remember the last Item mentioned and substitute that if the user types
"it" later, e.g.
take sword
drop it
-
Add Items with adjectives, like "rusty sword" and "silver sword".
-
Modify the code that calls on_take to check the return value. If on_take
returns False, then don't continue picking up the object. (I.e. prevent the
user from picking it up.)
- This enables you to add logic to
on_take to code things like "don't allow
the user to pick up the dirt unless they're holding the shovel.
-
Add monsters.
-
Add the attack verb that allows you to specify a monster to attack.
-
Add an on_attack method to the monster class.
-
Similar to the on_take return value modification, above, have on_attack
prevent the attack from succeeding unless the user possesses a sword item.
-
Come up with more stretch goals! The sky's the limit!
About
Introduction to Python basics
Resources
Readme
Activity
Custom properties
Stars
0 stars
Watchers
0 watching
Forks
0 forks
Report repository
Releases
Packages
Contributors
Languages