| | |
Projects for the Beginner
![]() |
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.
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
Below is the Python code for a simple console blackjack game. It's just you against the computer ...
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.
python Syntax (Toggle Plain Text)
# a simple blackjack game to figure out the ace_1_11 algorithm from random import choice as rc def total(hand): # how many aces in the hand aces = hand.count(11) # to complicate things a little the ace can be 11 or 1 if aces == 1: t = sum(hand) if t > 21: # evaluate the ace as a 1 t = t - 10 elif aces == 2: t = sum(hand) if t > 21: # evaluate one ace as a 1 t = t - 10 if t > 21: # evaluate second ace as a 1 t = t - 10 elif aces == 3: t = sum(hand) if t > 21: # evaluate one ace as a 1 t = t - 10 if t > 21: # evaluate second ace as a 1 t = t - 10 if t > 21: # evaluate third ace as a 1 t = t - 10 elif aces == 4: t = sum(hand) if t > 21: # evaluate one ace as a 1 t = t - 10 if t > 21: # evaluate second ace as a 1 t = t - 10 if t > 21: # evaluate third ace as a 1 t = t - 10 if t > 21: # evaluate fourth ace as a 1 t = t - 10 # could go for more aces here ... (odds?) else: t = sum(hand) return t # for a suit of cards in blackjack assume the following values # (jack, queen, king have value 10 ace has value 11, can be value 1) cards = [2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 11] # there are 4 suits per deck and usually several decks # this way you can assume the cards list to be an unlimited pool cwin = 0 # computer win counter pwin = 0 # player win counter while True: player = [] # draw 2 cards for the player to start player.append(rc(cards)) player.append(rc(cards)) pbust = False # player busted flag cbust = False # computer busted flag while True: # loop for the player's play ... tp = total(player) print "Player has these cards %s with a total value of %d" % (player, tp) if tp > 21: print "--> Player is busted!" pbust = True break elif tp == 21: print "\a BLACKJACK!" break else: hs = raw_input("Hit or Stand/Done (h or s): ").lower() if 'h' in hs: player.append(rc(cards)) else: break while True: # loop for the computer's play ... comp = [] comp.append(rc(cards)) comp.append(rc(cards)) # dealer generally stands around 17 or 18 while True: tc = total(comp) if tc < 18: comp.append(rc(cards)) else: break print "Computer has %s for a total of %d" % (comp, tc) # now figure out who won ... if tc > 21: print "--> Computer is busted!" cbust = True if pbust == False: print "Player wins!" pwin += 1 elif tc > tp: print "Computer won!" cwin += 1 elif tc == tp: print "A draw!" elif tp > tc: if pbust == False: print "Player won!" pwin += 1 elif cbust == False: print "Computer wins!" cwin += 1 break print "Wins, player = %d computer = %d" % (pwin, cwin) quit = raw_input("Press Enter (q to quit): ").lower() if 'q' in quit: break print "Thanks for playing blackjack with me!"
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!
•
•
Join Date: Jan 2007
Posts: 14
Reputation:
Solved Threads: 0
•
•
•
•
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.
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
•
•
Join Date: Jul 2006
Posts: 608
Reputation:
Solved Threads: 150
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.
python Syntax (Toggle Plain Text)
def total(hand): # how many aces in the hand aces = hand.count(11) # to complicate things a little the ace can be 11 or 1 if aces == 1: t = sum(hand) if t > 21: # evaluate the ace as a 1 t = t - 10 elif aces == 2: t = sum(hand) if t > 21: # evaluate one ace as a 1 t = t - 10 if t > 21: # evaluate second ace as a 1 t = t - 10 elif aces == 3: t = sum(hand) if t > 21: # evaluate one ace as a 1 t = t - 10 if t > 21: # evaluate second ace as a 1 t = t - 10 if t > 21: # evaluate third ace as a 1 t = t - 10 elif aces == 4: t = sum(hand) if t > 21: # evaluate one ace as a 1 t = t - 10 if t > 21: # evaluate second ace as a 1 t = t - 10 if t > 21: # evaluate third ace as a 1 t = t - 10 if t > 21: # evaluate fourth ace as a 1 t = t - 10 # could go for more aces here ... (odds?) else: t = sum(hand) return t
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
"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
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?
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
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
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!
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 ...
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.
python Syntax (Toggle Plain Text)
# Tkinter RGB color evaluator import Tkinter as tk def change(event): global rect # clear the present rectangle cv.delete(rect) # format RGB hexcolor string eg. red='#FF0000' xcolor = "#%02X%02X%02X" % (v_red.get(), v_green.get(), v_blue.get()) root.title("hexcolor = %s" % xcolor) rect = cv.create_rectangle(0,0,200,200,fill=xcolor) root = tk.Tk() v_red = tk.IntVar() red = tk.Scale(root, label="R", variable=v_red, from_=0, to=255) red.grid(row=0, column=0, padx=3, pady=3) red.bind('<B1-Motion>', change) v_green = tk.IntVar() green = tk.Scale(root, label="G", variable=v_green, from_=0, to=255) green.grid(row=0, column=1, padx=3, pady=3) green.bind('<B1-Motion>', change) v_blue = tk.IntVar() blue = tk.Scale(root, label="B", variable=v_blue, from_=0, to=255) blue.grid(row=0, column=2, padx=3, pady=3) blue.bind('<B1-Motion>', change) cv = tk.Canvas(root, width=200, height=200) cv.grid(row=0, column=3, padx=3, pady=3) rect = cv.create_rectangle(0,0,200,200,fill='black') root.mainloop()
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!
I was playing around with Python's calendar module ...
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.
python Syntax (Toggle Plain Text)
import calendar year = 2007 month = 3 # march # print out the current month's calendar calendar.prmonth(year, month) # get the week day header as a list day_list = calendar.weekheader(width=2).split() print day_list # assign the month's calendar to a matrix (list of lists) # each sublist is a week (unused days are zero) week_list = calendar.monthcalendar(year, month) for week in week_list: print week """ output --> March 2007 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'] [0, 0, 0, 1, 2, 3, 4] [5, 6, 7, 8, 9, 10, 11] [12, 13, 14, 15, 16, 17, 18] [19, 20, 21, 22, 23, 24, 25] [26, 27, 28, 29, 30, 31, 0] """
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!
Here are some well known approximations of pi:
There is still room to invent one approximation for pi that is easy to remember! Go and find it!
python Syntax (Toggle Plain Text)
# approximations of pi # 3/14 is the official 'Pi Day' # 3/14 is Albert Einstein's birthday (year 1879, born in Ulm) # as of feb2007 the pi approximation record is 1,241,100,000,000 digits import math # for your reference here is pi calculated to 77 decimals: 3.14159265358979323846264338327950288419716939937510582097494459230781640628620 # Chinese approximation, easy to remember # take 113355 then split in half ... p1 = 355/113.0 # Ramanujan1 or 'Chinese plus' (still 1, 3 or 5) p2 = 355/113.0 * (1 - 0.0003/3533) # deJerphanion, possibly easy to remember p3 = math.log(23 + 1/22.0 + 2/21.0) # Ramanujan2 p4 = 99*99/(2206*math.sqrt(2)) # Castellano p5 = 1.09999901 * 1.19999911 * 1.39999931 * 1.69999961 # Kochansky p6 = math.sqrt(40/3.0 - math.sqrt(12)) # Golden Ratio p7 = 3/5.0 * (3 + math.sqrt(5)) print "math.pi =", math.pi # 3.14159265359 print "Ramanujan1 =", p2 # 3.14159265359 print "deJerphanion =", p3 # 3.14159265393 print "Ramanujan2 =", p4 # 3.14159273001 print "Chinese =", p1 # 3.14159292035 print "Castellano =", p5 # 3.14159257347 print "Kochansky =", p6 # 3.14153333871 print "Golden Ratio =", p7 # 3.1416407865
Last edited by vegaseat; May 15th, 2007 at 8:36 pm. Reason: php tags changed
![]() |
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: Wing IDE & IronPython
- Next Thread: Printing dictionary sorted by value
| Thread Tools | Search this Thread |
.dll .net address advanced advice ajax aliased apax applicationreengineering array asp.net backend basic beginner bluetooth c++ calculator calling code college corners curved cx-freeze data dheeraj dictionary digital dynamic examples file forms function generator google gui images input ip java javadesktopapplications keycontrol launcher library link linux list loop mca microphone mouse newb newbie opensource output outsourcing php prime programming projectideas projects push py2exe pygame pyglet pyqt python random recursive retarded-mentally return rubyconf script skinning slicenotation software softwaredevelopment source sprite sqlite ssh string table text threading tlapse tooltip tutorial ubuntu unicode url urllib urllib2 variable vb.net voip webdevelopemnt whileloop wikipedia wxpython xlwt







