| | |
Projects for the Beginner
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
I did some detective work to find the stock trading value for a given ticker symbol. See if you can use the fruits of my labor and turn this into a more general portfolio tracker:
python Syntax (Toggle Plain Text)
# find the stock trading value for a given ticker symbol # tested with Python25 import urllib2 def extract(text, sub1, sub2): """ extract a substring from text between first occurances of substrings sub1 and sub2 """ return text.split(sub1, 1)[-1].split(sub2, 1)[0] ticker = 'GE' url = 'http://finance.yahoo.com/q?s='+ticker fh = urllib2.urlopen(url) ticker_html = fh.read() #print(ticker_html) for line in ticker_html.split('><'): if 'id="yfs_' in line: print(line) print('-'*70) # narrow it down for line in ticker_html.split('><'): if 'id="yfs_l' in line: print(line) print('-'*70) # narrow it down even more for line in ticker_html.split('><'): if 'id="yfs_l10_' in line: print(line) print(extract(line, '>', '<')) break
No one died when Clinton lied.
Here is the start of a Phone or Address Book:
Expand the data with the home address of the person.
How would you read the data file back into the program?
Also, query for data input and allow for editing of data.
python Syntax (Toggle Plain Text)
# create a dictionary of class instance values # can be expanded to an address book # note: email is a Python module, so use e_mail # snee class DataBook(object): def __init__(self, home, mobile, e_mail): self.home = home self.mobile = mobile self.e_mail = e_mail self.get_info() def get_info(self): sf = \ """Home Phone = %s Mobile Phone = %s Email = %s """ return sf % (self.home, self.mobile, self.e_mail) name_dic = {} # first set of data name = 'frank millato' home = '123-456-7890' mobile = '456-789-0123' e_mail = 'frank23@gmail.com' # the name string is the key and has to be unique name_dic[name] = DataBook(home, mobile, e_mail) # second set of data name = 'bob dork' home = '234-567-8901' mobile = '567-690-1234' e_mail = 'bob.dork@hotmail.com' name_dic[name] = DataBook(home, mobile, e_mail) # get bob's email name = 'bob dork' print( name_dic[name].e_mail ) print('-'*40) # get the info for all names added so far for key in name_dic: print( "Name = %s" % key ) print( name_dic[key].get_info() ) print('-'*40) # search for part of a name and find the mobile search = 'dork' for key in name_dic: if search in key: print( "%s has mobile = %s" % (key, name_dic[key].mobile) ) # to save the data, you can simply save it as a text file # where each line is name, home, mobile, e_mail filename = "Names1.txt" fout = open(filename, "w") for key in name_dic: k = name_dic[key] s = "%s,%s,%s,%s\n" % (key, k.home, k.mobile, k.e_mail) fout.write(s) fout.close() """ my output --> bob.dork@hotmail.com ---------------------------------------- Name = frank millato Home Phone = 123-456-7890 Mobile Phone = 456-789-0123 Email = frank23@gmail.com Name = bob dork Home Phone = 234-567-8901 Mobile Phone = 567-690-1234 Email = bob.dork@hotmail.com ---------------------------------------- bob dork has mobile = 567-690-1234 """
How would you read the data file back into the program?
Also, query for data input and allow for editing of data.
No one died when Clinton lied.
Here is a short code that allows you to list all the files in a given directory and its subdirectories:
Change the code in such a manner that, for instance, only image files are listed. Image files would have extensions like .jpg .png .gif .bmp an so on.
python Syntax (Toggle Plain Text)
#!/usr/bin/env python2.5 # list all files in a directory tree using recursion # shows full file paths of all files in subdirectories too # works with Python2 and Python3 import os def mylister(currdir, mylist=[]): """default mylist becomes static""" #print( "looking at %s" % currdir ) # test for file in os.listdir(currdir): # add directory to filename path = os.path.join(currdir, file) if not os.path.isdir(path): #print(path) # test mylist.append(path) else: # recurse into subdirectories mylister(path) return mylist # this allows the module mylister to be tested if __name__ == '__main__': # pick a folder/directory # for Windows use something like this #folder = r"C:\Temp" # for Linux use something like this folder = "/home/dell/Documents" path_list = mylister(folder) for path in path_list: print(path) """my partial result --> /home/dell/Documents/about.html /home/dell/Documents/_sources/user/basics.rec.txt /home/dell/Documents/_sources/user/performance.txt /home/dell/Documents/_sources/user/basics.indexing.txt /home/dell/Documents/_sources/user/basics.txt /home/dell/Documents/_sources/user/basics.creation.txt /home/dell/Documents/_sources/user/misc.txt /home/dell/Documents/_sources/user/index.txt ... """
No one died when Clinton lied.
The module turtle that comes with Python makes for interesting projects. Here is a function that draws a hexagon:
If you run this code, you will see that the hexagon rests on its side. Your challenge will be to rewrite the function so it will draw the hexagon resting on its tip.
python Syntax (Toggle Plain Text)
# explore module turtle (uses the Tkinter GUI toolkit) # usually included in the Python2 and Python3 installation # a function to draw 6 turtle lines to form a hexagon # snee import turtle as tu tu.title('hexagon function') def t_hexagon(x, y, side, color): """ draw an equilateral hexagon, each side has length=side starting at coordinates x, y (upper side, right corner) """ tu.up() # pen up tu.goto(x, y) tu.down() # pen down tu.color(color) for k in range(6): tu.right(360/6) tu.forward(side) # optional ('normal' is default) ... # values for speed are 'fastest' (no delay), 'fast', (delay 5ms), # 'normal' (delay 10ms), 'slow' (delay 15ms), 'slowest' (delay 20ms) #tu.speed('fastest') # optional pen width (default is 1) tu.width(2) # turtle by default starts at x=0, y=0 # wich is the center of a (ca. 450x550) window # pick +x units to the right, +y units up, # -x units to the left, -y units down x = 50 y = 100 side = 100 color = 'red' t_hexagon(x, y, side, color) # keep showing until window corner x is clicked tu.done()
Last edited by sneekula; Sep 13th, 2009 at 8:50 pm.
No one died when Clinton lied.
0
#198 Oct 6th, 2009
I don't know if this is appropriate for a beginner but I suggest designing a simple TicTacToe game for 1on1 mode because vs the computer is way harder to program. Try to create the 3x3 play field and check whether a player wins or loses.
0
#200 Oct 15th, 2009
Write a program that calculates the day of the week for a date from 1900 onward having in mind that 1 January 1900 fell on a Monday
The program should be able to calculate any day for a year >= 1900

Perhaps a GUI for it aswell....
Make sure you check for leap years...
The program should be able to calculate any day for a year >= 1900

Perhaps a GUI for it aswell....

Make sure you check for leap years...
Last edited by masterofpuppets; Oct 15th, 2009 at 11:44 am.
![]() |
Similar Threads
- Ideal project for a beginner? (Python)
- Hep finding C++ Projects (Python)
- Help finding C++ Projects (C++)
- New task from Projects for the beginner: (Python)
Other Threads in the Python Forum
- Previous Thread: Calling Function?
- Next Thread: How to avoid python shebang line on linux.
| Thread Tools | Search this Thread |
.dll accessdenied advice ajax aliased arax bash basic beginner book c# c++ calculator class code college console convert corners csv cturtle curves data dictionary digital edit examples file function generator gui halp homework ideas iframe infosec input ip itconsulting java javadesktopapplications keyboard keycontrol leftmouse line linux list lists mca module mysql obexftp parameters path php prime programming project projectideas projects py2exe pygame pygtk pyopengl python random raw_input read redirect retarded-mentally reverse ruby script simple skinning software softwaredevelopment sprite sqlite ssh string sudokusolver table terminal threading time tkinter tricks tutorial ubuntu unicode urllib urllib2 variable verify visual voip web-scrape write wxpython







