Projects for the Beginner

Reply

Join Date: Aug 2005
Posts: 1,523
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 169
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: Projects for the Beginner

 
0
  #101
Dec 5th, 2006
Take a look at:
http://www.daniweb.com/code/snippet604.html
and use this database templet to create an address book. You can add a 'print address labels' feature to it.

The easiest would be to write the address labels to a file and use one of the editors or word processors to actually print it out to the printer.
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,972
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: 920
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Projects for the Beginner

 
0
  #102
Jan 7th, 2007
Below is the Python code for a simple console blackjack game. It's just you against the computer ...
  1. # a simple blackjack game to figure out the ace_1_11 algorithm
  2. from random import choice as rc
  3. def total(hand):
  4. # how many aces in the hand
  5. aces = hand.count(11)
  6. # to complicate things a little the ace can be 11 or 1
  7. if aces == 1:
  8. t = sum(hand)
  9. if t > 21:
  10. # evaluate the ace as a 1
  11. t = t - 10
  12. elif aces == 2:
  13. t = sum(hand)
  14. if t > 21:
  15. # evaluate one ace as a 1
  16. t = t - 10
  17. if t > 21:
  18. # evaluate second ace as a 1
  19. t = t - 10
  20. elif aces == 3:
  21. t = sum(hand)
  22. if t > 21:
  23. # evaluate one ace as a 1
  24. t = t - 10
  25. if t > 21:
  26. # evaluate second ace as a 1
  27. t = t - 10
  28. if t > 21:
  29. # evaluate third ace as a 1
  30. t = t - 10
  31. elif aces == 4:
  32. t = sum(hand)
  33. if t > 21:
  34. # evaluate one ace as a 1
  35. t = t - 10
  36. if t > 21:
  37. # evaluate second ace as a 1
  38. t = t - 10
  39. if t > 21:
  40. # evaluate third ace as a 1
  41. t = t - 10
  42. if t > 21:
  43. # evaluate fourth ace as a 1
  44. t = t - 10
  45. # could go for more aces here ... (odds?)
  46. else:
  47. t = sum(hand)
  48. return t
  49.  
  50. # for a suit of cards in blackjack assume the following values
  51. # (jack, queen, king have value 10 ace has value 11, can be value 1)
  52. cards = [2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11]
  53. # there are 4 suits per deck and usually several decks
  54. # this way you can assume the cards list to be an unlimited pool
  55. cwin = 0 # computer win counter
  56. pwin = 0 # player win counter
  57. while True:
  58. player = []
  59. # draw 2 cards for the player to start
  60. player.append(rc(cards))
  61. player.append(rc(cards))
  62. pbust = False # player busted flag
  63. cbust = False # computer busted flag
  64. while True:
  65. # loop for the player's play ...
  66. tp = total(player)
  67. print "Player has these cards %s with a total value of %d" % (player, tp)
  68. if tp > 21:
  69. print "--> Player is busted!"
  70. pbust = True
  71. break
  72. elif tp == 21:
  73. print "\a BLACKJACK!"
  74. break
  75. else:
  76. hs = raw_input("Hit or Stand/Done (h or s): ").lower()
  77. if 'h' in hs:
  78. player.append(rc(cards))
  79. else:
  80. break
  81. while True:
  82. # loop for the computer's play ...
  83. comp = []
  84. comp.append(rc(cards))
  85. comp.append(rc(cards))
  86. # dealer generally stands around 17 or 18
  87. while True:
  88. tc = total(comp)
  89. if tc < 18:
  90. comp.append(rc(cards))
  91. else:
  92. break
  93. print "Computer has %s for a total of %d" % (comp, tc)
  94. # now figure out who won ...
  95. if tc > 21:
  96. print "--> Computer is busted!"
  97. cbust = True
  98. if pbust == False:
  99. print "Player wins!"
  100. pwin += 1
  101. elif tc > tp:
  102. print "Computer won!"
  103. cwin += 1
  104. elif tc == tp:
  105. print "A draw!"
  106. elif tp > tc:
  107. if pbust == False:
  108. print "Player won!"
  109. pwin += 1
  110. elif cbust == False:
  111. print "Computer wins!"
  112. cwin += 1
  113. break
  114. print
  115. print "Wins, player = %d computer = %d" % (pwin, cwin)
  116. quit = raw_input("Press Enter (q to quit): ").lower()
  117. if 'q' in quit:
  118. break
  119. print
  120. print
  121. print "Thanks for playing blackjack with me!"
Click on "Toggle Plain Text" so you can highlight and copy the code to your editor.

You are urged to improve the game by adding more players and maybe display real cards using a GUI toolkit.
Last edited by vegaseat; Mar 1st, 2007 at 4:30 pm. Reason: code=python toggle text
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 14
Reputation: Extremist is an unknown quantity at this point 
Solved Threads: 0
Extremist Extremist is offline Offline
Newbie Poster

Re: Projects for the Beginner

 
0
  #103
Jan 10th, 2007
Originally Posted by vegaseat View Post
After you got the basics of Python under your belt, the best way to get a good knowledge of the language and improve your coding skills is to start on a project you are interested in. This sticky is dedicated to a list of just such projects.

If you know a good project, please post it here. If you have questions, start your own thread and don't clutter the sticky.
I guess this one is a bit advanced but it will seriously help you (It is my current personal project)
Write a program that helps determine hand-eye coordination. (A good GUI toolkit is wxPython) First test the hand-eye coordination skills of the user by letting a few images/buttons/words or whatever appear randomly and they have to click on it. So take the current time which the person takes to click on the and calculate the time. the amount of time the person take will determine their hand-eye coordination ability
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: Projects for the Beginner

 
1
  #104
Jan 11th, 2007
Also in the blackjack game: find a way to make the total() function deal with aces in a general way so that vega's worry about adding more aces can be satisfied.

  1. def total(hand):
  2. # how many aces in the hand
  3. aces = hand.count(11)
  4. # to complicate things a little the ace can be 11 or 1
  5. if aces == 1:
  6. t = sum(hand)
  7. if t > 21:
  8. # evaluate the ace as a 1
  9. t = t - 10
  10. elif aces == 2:
  11. t = sum(hand)
  12. if t > 21:
  13. # evaluate one ace as a 1
  14. t = t - 10
  15. if t > 21:
  16. # evaluate second ace as a 1
  17. t = t - 10
  18. elif aces == 3:
  19. t = sum(hand)
  20. if t > 21:
  21. # evaluate one ace as a 1
  22. t = t - 10
  23. if t > 21:
  24. # evaluate second ace as a 1
  25. t = t - 10
  26. if t > 21:
  27. # evaluate third ace as a 1
  28. t = t - 10
  29. elif aces == 4:
  30. t = sum(hand)
  31. if t > 21:
  32. # evaluate one ace as a 1
  33. t = t - 10
  34. if t > 21:
  35. # evaluate second ace as a 1
  36. t = t - 10
  37. if t > 21:
  38. # evaluate third ace as a 1
  39. t = t - 10
  40. if t > 21:
  41. # evaluate fourth ace as a 1
  42. t = t - 10
  43. # could go for more aces here ... (odds?)
  44. else:
  45. t = sum(hand)
  46. return t
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,523
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 169
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: Projects for the Beginner

 
0
  #105
Jan 12th, 2007
This is a project that can go from beginner to advanced level:

"Data Mining" is an increasingly popular field and Python is pretty good at it. To data-mine HTML pages on the Web you can use an HTML Scraper like "Beautiful Soup" from:
http://www.crummy.com/software/BeautifulSoup/

More involved are data scrapers like Orange from:
http://www.ailab.si/orange
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,523
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 169
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: Projects for the Beginner

 
0
  #106
Jan 12th, 2007
With this project you need to do some "googling" to get the needed information.

If the USA would like to replace all the gasoline presently consumed here with ethanol, how many bushels of corn would US farmers have to grow to produce the ethanol.

Are there enough acres of farmland in the US to do this?
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,972
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: 920
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Projects for the Beginner

 
0
  #107
Jan 15th, 2007
Here are some projects that require a little library work and Google searching at first.

1) Write a simple Python code to C++ code converter
2) Write a small Python "Expert System"
3) Write a Python program the applies Artificial Intelligence (AI)
4) Write a Python "Data Mining" program
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,972
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: 920
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Projects for the Beginner

 
0
  #108
Jan 16th, 2007
Here is a simple Tkinter GUI program that has three sliders for the red, green, blue color values that make up the rgb-colors of a canvas rectangle. Move the sliders (scales in tk) and create 16777216 different colors ...
  1. # Tkinter RGB color evaluator
  2.  
  3. import Tkinter as tk
  4.  
  5. def change(event):
  6. global rect
  7. # clear the present rectangle
  8. cv.delete(rect)
  9. # format RGB hexcolor string eg. red='#FF0000'
  10. xcolor = "#%02X%02X%02X" % (v_red.get(), v_green.get(), v_blue.get())
  11. root.title("hexcolor = %s" % xcolor)
  12. rect = cv.create_rectangle(0,0,200,200,fill=xcolor)
  13.  
  14.  
  15. root = tk.Tk()
  16.  
  17. v_red = tk.IntVar()
  18. red = tk.Scale(root, label="R", variable=v_red, from_=0, to=255)
  19. red.grid(row=0, column=0, padx=3, pady=3)
  20. red.bind('<B1-Motion>', change)
  21.  
  22. v_green = tk.IntVar()
  23. green = tk.Scale(root, label="G", variable=v_green, from_=0, to=255)
  24. green.grid(row=0, column=1, padx=3, pady=3)
  25. green.bind('<B1-Motion>', change)
  26.  
  27. v_blue = tk.IntVar()
  28. blue = tk.Scale(root, label="B", variable=v_blue, from_=0, to=255)
  29. blue.grid(row=0, column=2, padx=3, pady=3)
  30. blue.bind('<B1-Motion>', change)
  31.  
  32. cv = tk.Canvas(root, width=200, height=200)
  33. cv.grid(row=0, column=3, padx=3, pady=3)
  34. rect = cv.create_rectangle(0,0,200,200,fill='black')
  35.  
  36. root.mainloop()
Your mission is to create a fourth slider that changes the rectangle's colors along the scale of a rainbow (red to blue).

An extra (Jeff will like that):
If you want to experiment with class objects, change the code so it uses a class.
Last edited by vegaseat; Jan 16th, 2007 at 1:16 pm. Reason: fixed missing lines in code field
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,972
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: 920
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Projects for the Beginner

 
0
  #109
Feb 3rd, 2007
I was playing around with Python's calendar module ...
  1. import calendar
  2. year = 2007
  3. month = 3 # march
  4. # print out the current month's calendar
  5. calendar.prmonth(year, month)
  6. print
  7. # get the week day header as a list
  8. day_list = calendar.weekheader(width=2).split()
  9. print day_list
  10. print
  11. # assign the month's calendar to a matrix (list of lists)
  12. # each sublist is a week (unused days are zero)
  13. week_list = calendar.monthcalendar(year, month)
  14. for week in week_list:
  15. print week
  16. """
  17. output -->
  18. March 2007
  19. Mo Tu We Th Fr Sa Su
  20. 1 2 3 4
  21. 5 6 7 8 9 10 11
  22. 12 13 14 15 16 17 18
  23. 19 20 21 22 23 24 25
  24. 26 27 28 29 30 31
  25. ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']
  26. [0, 0, 0, 1, 2, 3, 4]
  27. [5, 6, 7, 8, 9, 10, 11]
  28. [12, 13, 14, 15, 16, 17, 18]
  29. [19, 20, 21, 22, 23, 24, 25]
  30. [26, 27, 28, 29, 30, 31, 0]
  31. """
One could create a 7x6 matrix of buttons, let's say with the Tkinter GUI toolkit and fill the buttons with the week_list info. Then use the day_list info as a header. You will have a monthly calendar as a bunch of buttons (zeros would be empty).

Now, one could press a particular day's button and bring up an entry with the date. The user writes in that day's memo (appointmnets, thing to do) and saves it as a dictionary with the date as the key, so it can be linked with that date for later use. You could finish this one.
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 137
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: Projects for the Beginner

 
0
  #110
Feb 4th, 2007
Here are some well known approximations of pi:
  1. # approximations of pi
  2. # 3/14 is the official 'Pi Day'
  3. # 3/14 is Albert Einstein's birthday (year 1879, born in Ulm)
  4. # as of feb2007 the pi approximation record is 1,241,100,000,000 digits
  5.  
  6. import math
  7.  
  8. # for your reference here is pi calculated to 77 decimals:
  9. 3.14159265358979323846264338327950288419716939937510582097494459230781640628620
  10.  
  11. # Chinese approximation, easy to remember
  12. # take 113355 then split in half ...
  13. p1 = 355/113.0
  14.  
  15. # Ramanujan1 or 'Chinese plus' (still 1, 3 or 5)
  16. p2 = 355/113.0 * (1 - 0.0003/3533)
  17.  
  18. # deJerphanion, possibly easy to remember
  19. p3 = math.log(23 + 1/22.0 + 2/21.0)
  20.  
  21. # Ramanujan2
  22. p4 = 99*99/(2206*math.sqrt(2))
  23.  
  24. # Castellano
  25. p5 = 1.09999901 * 1.19999911 * 1.39999931 * 1.69999961
  26.  
  27. # Kochansky
  28. p6 = math.sqrt(40/3.0 - math.sqrt(12))
  29.  
  30. # Golden Ratio
  31. p7 = 3/5.0 * (3 + math.sqrt(5))
  32.  
  33. print "math.pi =", math.pi # 3.14159265359
  34. print "Ramanujan1 =", p2 # 3.14159265359
  35. print "deJerphanion =", p3 # 3.14159265393
  36. print "Ramanujan2 =", p4 # 3.14159273001
  37. print "Chinese =", p1 # 3.14159292035
  38. print "Castellano =", p5 # 3.14159257347
  39. print "Kochansky =", p6 # 3.14153333871
  40. print "Golden Ratio =", p7 # 3.1416407865
There is still room to invent one approximation for pi that is easy to remember! Go and find it!
Last edited by vegaseat; May 15th, 2007 at 8:36 pm. Reason: php tags changed
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