Projects for the Beginner

Reply

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

Re: Projects for the Beginner

 
0
  #91
Oct 5th, 2006
Create a letter pyramid in Python.
  1. let's say the user enters H
  2. the pyramid should like this:
  3. A
  4. ABA
  5. ABCBA
  6. ABCDCBA
  7. ABCDEDCBA
  8. ABCDEFEDCBA
  9. ABCDEFGFEDCBA
  10. ABCDEFGHGFEDCBA
  11.  
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,514
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 168
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: Projects for the Beginner

 
1
  #92
Oct 5th, 2006
Here is a small Python program for an online gem store:
  1. # the online gem store
  2.  
  3. def add2cart(item, amount):
  4. """build up the cart list"""
  5. price = amount*list_of_gems[item-1][1]
  6. cart.append((item-1, amount, price))
  7.  
  8. # list of (gem, price) tuples
  9. list_of_gems = [('ruby', 99.99), ('emerald', 72.50), ('topaz', 23.95), ('agate', 14.00)]
  10.  
  11. # will be list of (item#, amount, price) tuples
  12. cart = []
  13. # total of all purchases
  14. total = 0
  15.  
  16. while True:
  17. print '-'*32, '\n\t\tList of Gems\n', '-'*32
  18. for k in range(len(list_of_gems)):
  19. # starts with item_number to enter
  20. print '%d\t%8s for $%0.2f each' % (k+1, list_of_gems[k][0], list_of_gems[k][1])
  21. try:
  22. item = int(raw_input('\nPlease select a gem (by number): '))
  23. if item > len(list_of_gems):
  24. print "item number too high! Try again!"
  25. item = 0
  26. except ValueError:
  27. print "Item number not correct! Try again!"
  28. item = 0
  29. try:
  30. if item > 0:
  31. amount = int(raw_input('Enter quantity of selected item: '))
  32. except ValueError:
  33. print "Amount not correct, has to be whole number! Try again!"
  34. amount = 0
  35. if item > 0 and amount > 0:
  36. add2cart(item, amount)
  37. else:
  38. print "Please enter item and amount again!\a\n"
  39.  
  40. # added .lower() so user can enter 'No' or 'NO' or 'no'
  41. more = raw_input('Want to buy something else (yes/no)? ').lower()
  42. # user can enter 'no' or just 'n'
  43. if 'n' in more:
  44. print
  45. print "Thank you for your order, here is your purchase detail:"
  46. break
  47.  
  48. print '\n', '~'*38
  49. for x in range(len(cart)):
  50. item_number = cart[x][0]
  51. gem = list_of_gems[item_number][0]
  52. price = list_of_gems[item_number][1]
  53. quantity = cart[x][1]
  54. total_per_item = cart[x][2]
  55. print '%4d %8s @ $%0.2f = $%5.2f' % (quantity, gem, price, total_per_item)
  56. total += total_per_item
  57.  
  58. print '~'*38
  59. print "\t%18s = $%4.2f" % ('TOTAL', total)
There are a few problems for you to iron out. If the customer enters an order for the same gem more than once, the program should consolidate the order for that paticular gem. Also the customer should be asked at the end, if the order is correct. If not, a user-friendly correction mechanism should be built in.
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,514
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 168
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: Projects for the Beginner

 
0
  #93
Oct 7th, 2006
Create a database you can search for names, phone numbers, addresses, hobbies, aspirations and so on.

You could use something like snippet:
http://www.daniweb.com/code/snippet390.html

However, you need to improve it so you can update and save and load the data as a file.
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,955
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: 917
Moderator
vegaseat's Avatar
vegaseat vegaseat is online now Online
DaniWeb's Hypocrite

Re: Projects for the Beginner

 
0
  #94
Oct 16th, 2006
Just a sometimes elusive Python/Tkinter rectangle. Could that be turned into a game?
  1. # click on the red rectangle ...
  2.  
  3. from Tkinter import *
  4. import random
  5.  
  6. def create_rect():
  7. chance = random.sample(range(1, 250), 4)
  8. print chance # test eg. [72, 206, 116, 166]
  9. canvas.create_rectangle(chance, fill="red")
  10.  
  11. def check_rect(event):
  12. rect = canvas.find_overlapping(event.x, event.y, event.x, event.y)
  13. if rect:
  14. # delete old rectangle
  15. canvas.delete(rect)
  16. # create new rectangle
  17. create_rect()
  18.  
  19. root = Tk()
  20. root.title("click on red")
  21.  
  22. canvas = Canvas(root, height=250, width=250, bg="yellow")
  23. canvas.pack()
  24.  
  25. # create the starting random rectangle
  26. create_rect()
  27.  
  28. # respond to left mouse button click
  29. canvas.bind("<Button-1>", check_rect)
  30.  
  31. root.mainloop()
Click on "Toggle Plain Text" so you can highlight and copy the code to your editor without the line numbers.
Last edited by vegaseat; Mar 1st, 2007 at 4:28 pm. Reason: code=python tag
May 'the Google' be with you!
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
  #95
Oct 17th, 2006
Write a function primes(n) that returns a list of primes less than n.

primes(13)
[2,3,5,7,11]
primes(25.2)
[2,3,5,7,11,13,17,19,23]

If you don't know any clever ways to generate primes, Google for the "Sieve of Eratosthenes"
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
  #96
Oct 17th, 2006
Project for the advanced: write code to hack into Ene's gem store above from a remote zombie and change all the prices to $19.99.

:lol:
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
  #97
Oct 18th, 2006
Write Human vs. Computer Battle Ship Game in Python. Tkinter should/could do it for the graphics.

Possible setup:
Battleship (1) = 4 adjoining squares
Cruiser (2) = 3 adjoining squares
Destroyer (3) = 2 adjoining squares
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,955
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: 917
Moderator
vegaseat's Avatar
vegaseat vegaseat is online now Online
DaniWeb's Hypocrite

Re: Projects for the Beginner

 
0
  #98
Oct 21st, 2006
The code below shows a birthday message on fairly large banner using the Tkinter GUI module.
  1. # a simple banner using Tkinter
  2.  
  3. from Tkinter import *
  4.  
  5. #create the form
  6. root = Tk()
  7.  
  8. canvas1 = Canvas(root, height=100, width=600, bg="white")
  9. canvas1.pack()
  10.  
  11. str1 = "Happy Birthday Ursula!"
  12. x = 20
  13. y = 20
  14. text1 = canvas1.create_text(x, y, anchor=NW, text=str1, font=('times', 32, 'bold'), fill='red')
  15.  
  16. root.mainloop()
Now improve the code so each of the letters shows up in a different color following the colorpattern of a rainbow.
Last edited by vegaseat; Mar 1st, 2007 at 4:29 pm. Reason: code=python tag
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 128
Reputation: LaMouche is on a distinguished road 
Solved Threads: 19
LaMouche's Avatar
LaMouche LaMouche is offline Offline
Junior Poster

Re: Projects for the Beginner

 
1
  #99
Oct 29th, 2006
Create a game similar to "Wheel of Fortune." Have a list of words, and have the program randomly pick a word from the list. Then, let the user guess 5 or so letters, and after each guess, show the word he or she is guessing in this format:

  1. - Say the word is "jelly" and they guessed "l"
  2.  
  3. --ll-

After the five letters, have the user guess the word. If they get it right, congratulate them. Otherwise, tell them the correct word.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 1
Reputation: amadeobellotti is an unknown quantity at this point 
Solved Threads: 0
amadeobellotti amadeobellotti is offline Offline
Newbie Poster

Re: Projects for the Beginner

 
0
  #100
Nov 15th, 2006
What I like to do is to take an idea that you might think is really easy and see how small you can make the code I've made a script that prints Fibonacci's numbers in 66 bytes. its challenging but fun at the same time it pushes your skill beyond what a simple prgramming idea works.
  1. f=[0,1]
  2. for i in range(input()-2):
  3. f.append(f[-2]+f[-1])
  4. print f
btw if someone knows a way to make this smaller email me please
Last edited by vegaseat; Nov 18th, 2006 at 10:49 am. Reason: Fibonacci
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC