Projects for the Beginner

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2006
Posts: 2,279
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 176
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Projects for the Beginner

 
0
  #191
May 14th, 2009
Write a program that lists all the fonts available on your computer, and apply the selected font to a sample text.
Last edited by sneekula; May 14th, 2009 at 10:54 am.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,546
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 174
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: Projects for the Beginner

 
0
  #192
May 24th, 2009
Write a function that groups a large number into thousands. For instance
123456789 --> 123,456,789
or
1234567.89 --> 1,234,567.89
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,279
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 176
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Projects for the Beginner

 
0
  #193
Jun 17th, 2009
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:
  1. # find the stock trading value for a given ticker symbol
  2. # tested with Python25
  3.  
  4. import urllib2
  5.  
  6. def extract(text, sub1, sub2):
  7. """
  8. extract a substring from text between first
  9. occurances of substrings sub1 and sub2
  10. """
  11. return text.split(sub1, 1)[-1].split(sub2, 1)[0]
  12.  
  13.  
  14. ticker = 'GE'
  15. url = 'http://finance.yahoo.com/q?s='+ticker
  16. fh = urllib2.urlopen(url)
  17. ticker_html = fh.read()
  18.  
  19. #print(ticker_html)
  20.  
  21. for line in ticker_html.split('><'):
  22. if 'id="yfs_' in line:
  23. print(line)
  24.  
  25. print('-'*70)
  26.  
  27. # narrow it down
  28. for line in ticker_html.split('><'):
  29. if 'id="yfs_l' in line:
  30. print(line)
  31.  
  32. print('-'*70)
  33.  
  34. # narrow it down even more
  35. for line in ticker_html.split('><'):
  36. if 'id="yfs_l10_' in line:
  37. print(line)
  38. print(extract(line, '>', '<'))
  39. break
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,279
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 176
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Projects for the Beginner

 
0
  #194
Jun 28th, 2009
Here is the start of a Phone or Address Book:
  1. # create a dictionary of class instance values
  2. # can be expanded to an address book
  3. # note: email is a Python module, so use e_mail
  4. # snee
  5.  
  6. class DataBook(object):
  7. def __init__(self, home, mobile, e_mail):
  8. self.home = home
  9. self.mobile = mobile
  10. self.e_mail = e_mail
  11. self.get_info()
  12.  
  13. def get_info(self):
  14. sf = \
  15. """Home Phone = %s
  16. Mobile Phone = %s
  17. Email = %s
  18. """
  19. return sf % (self.home, self.mobile, self.e_mail)
  20.  
  21.  
  22. name_dic = {}
  23.  
  24. # first set of data
  25. name = 'frank millato'
  26. home = '123-456-7890'
  27. mobile = '456-789-0123'
  28. e_mail = 'frank23@gmail.com'
  29.  
  30. # the name string is the key and has to be unique
  31. name_dic[name] = DataBook(home, mobile, e_mail)
  32.  
  33. # second set of data
  34. name = 'bob dork'
  35. home = '234-567-8901'
  36. mobile = '567-690-1234'
  37. e_mail = 'bob.dork@hotmail.com'
  38.  
  39. name_dic[name] = DataBook(home, mobile, e_mail)
  40.  
  41. # get bob's email
  42. name = 'bob dork'
  43. print( name_dic[name].e_mail )
  44.  
  45. print('-'*40)
  46.  
  47. # get the info for all names added so far
  48. for key in name_dic:
  49. print( "Name = %s" % key )
  50. print( name_dic[key].get_info() )
  51.  
  52. print('-'*40)
  53.  
  54. # search for part of a name and find the mobile
  55. search = 'dork'
  56. for key in name_dic:
  57. if search in key:
  58. print( "%s has mobile = %s" % (key, name_dic[key].mobile) )
  59.  
  60.  
  61. # to save the data, you can simply save it as a text file
  62. # where each line is name, home, mobile, e_mail
  63. filename = "Names1.txt"
  64. fout = open(filename, "w")
  65. for key in name_dic:
  66. k = name_dic[key]
  67. s = "%s,%s,%s,%s\n" % (key, k.home, k.mobile, k.e_mail)
  68. fout.write(s)
  69. fout.close()
  70.  
  71. """
  72. my output -->
  73. bob.dork@hotmail.com
  74. ----------------------------------------
  75. Name = frank millato
  76. Home Phone = 123-456-7890
  77. Mobile Phone = 456-789-0123
  78. Email = frank23@gmail.com
  79.  
  80. Name = bob dork
  81. Home Phone = 234-567-8901
  82. Mobile Phone = 567-690-1234
  83. Email = bob.dork@hotmail.com
  84.  
  85. ----------------------------------------
  86. bob dork has mobile = 567-690-1234
  87. """
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.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,279
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 176
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Projects for the Beginner

 
0
  #195
Aug 1st, 2009
Write a program that goes through a folder of source/text files and lists all the file names that contain a given search word (or combination of search words).
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,279
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 176
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Projects for the Beginner

 
0
  #196
Aug 18th, 2009
Here is a short code that allows you to list all the files in a given directory and its subdirectories:
  1. #!/usr/bin/env python2.5
  2.  
  3. # list all files in a directory tree using recursion
  4. # shows full file paths of all files in subdirectories too
  5. # works with Python2 and Python3
  6.  
  7. import os
  8.  
  9. def mylister(currdir, mylist=[]):
  10. """default mylist becomes static"""
  11. #print( "looking at %s" % currdir ) # test
  12. for file in os.listdir(currdir):
  13. # add directory to filename
  14. path = os.path.join(currdir, file)
  15. if not os.path.isdir(path):
  16. #print(path) # test
  17. mylist.append(path)
  18. else:
  19. # recurse into subdirectories
  20. mylister(path)
  21. return mylist
  22.  
  23. # this allows the module mylister to be tested
  24. if __name__ == '__main__':
  25. # pick a folder/directory
  26. # for Windows use something like this
  27. #folder = r"C:\Temp"
  28. # for Linux use something like this
  29. folder = "/home/dell/Documents"
  30. path_list = mylister(folder)
  31. for path in path_list:
  32. print(path)
  33.  
  34. """my partial result -->
  35. /home/dell/Documents/about.html
  36. /home/dell/Documents/_sources/user/basics.rec.txt
  37. /home/dell/Documents/_sources/user/performance.txt
  38. /home/dell/Documents/_sources/user/basics.indexing.txt
  39. /home/dell/Documents/_sources/user/basics.txt
  40. /home/dell/Documents/_sources/user/basics.creation.txt
  41. /home/dell/Documents/_sources/user/misc.txt
  42. /home/dell/Documents/_sources/user/index.txt
  43. ...
  44. """
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.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,279
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 176
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Re: Projects for the Beginner

 
0
  #197
Sep 13th, 2009
The module turtle that comes with Python makes for interesting projects. Here is a function that draws a hexagon:
  1. # explore module turtle (uses the Tkinter GUI toolkit)
  2. # usually included in the Python2 and Python3 installation
  3. # a function to draw 6 turtle lines to form a hexagon
  4. # snee
  5.  
  6. import turtle as tu
  7.  
  8. tu.title('hexagon function')
  9.  
  10. def t_hexagon(x, y, side, color):
  11. """
  12. draw an equilateral hexagon, each side has length=side
  13. starting at coordinates x, y (upper side, right corner)
  14. """
  15. tu.up() # pen up
  16. tu.goto(x, y)
  17. tu.down() # pen down
  18. tu.color(color)
  19. for k in range(6):
  20. tu.right(360/6)
  21. tu.forward(side)
  22.  
  23. # optional ('normal' is default) ...
  24. # values for speed are 'fastest' (no delay), 'fast', (delay 5ms),
  25. # 'normal' (delay 10ms), 'slow' (delay 15ms), 'slowest' (delay 20ms)
  26. #tu.speed('fastest')
  27.  
  28. # optional pen width (default is 1)
  29. tu.width(2)
  30.  
  31. # turtle by default starts at x=0, y=0
  32. # wich is the center of a (ca. 450x550) window
  33. # pick +x units to the right, +y units up,
  34. # -x units to the left, -y units down
  35. x = 50
  36. y = 100
  37. side = 100
  38. color = 'red'
  39. t_hexagon(x, y, side, color)
  40.  
  41. # keep showing until window corner x is clicked
  42. tu.done()
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.
Last edited by sneekula; Sep 13th, 2009 at 8:50 pm.
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 226
Reputation: masterofpuppets is an unknown quantity at this point 
Solved Threads: 55
masterofpuppets's Avatar
masterofpuppets masterofpuppets is offline Offline
Posting Whiz in Training
 
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.
My site ->> http://8masterofpuppets8.webs.com/
"My belief is stronger than your doubt."
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,028
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 932
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite
 
0
  #199
Oct 6th, 2009
Write a function that returns the longer of two strings or the first string if equal in length.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 226
Reputation: masterofpuppets is an unknown quantity at this point 
Solved Threads: 55
masterofpuppets's Avatar
masterofpuppets masterofpuppets is offline Offline
Posting Whiz in Training
 
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...
Last edited by masterofpuppets; Oct 15th, 2009 at 11:44 am.
My site ->> http://8masterofpuppets8.webs.com/
"My belief is stronger than your doubt."
Reply With Quote Quick reply to this message  
Reply

Tags
beginner, projects, python

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC