| | |
Projects for the Beginner
![]() |
Create a letter pyramid in Python.
Python Syntax (Toggle Plain Text)
let's say the user enters H the pyramid should like this: A ABA ABCBA ABCDCBA ABCDEDCBA ABCDEFEDCBA ABCDEFGFEDCBA ABCDEFGHGFEDCBA
drink her pretty
Here is a small Python program for an online gem store:
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.
Python Syntax (Toggle Plain Text)
# the online gem store def add2cart(item, amount): """build up the cart list""" price = amount*list_of_gems[item-1][1] cart.append((item-1, amount, price)) # list of (gem, price) tuples list_of_gems = [('ruby', 99.99), ('emerald', 72.50), ('topaz', 23.95), ('agate', 14.00)] # will be list of (item#, amount, price) tuples cart = [] # total of all purchases total = 0 while True: print '-'*32, '\n\t\tList of Gems\n', '-'*32 for k in range(len(list_of_gems)): # starts with item_number to enter print '%d\t%8s for $%0.2f each' % (k+1, list_of_gems[k][0], list_of_gems[k][1]) try: item = int(raw_input('\nPlease select a gem (by number): ')) if item > len(list_of_gems): print "item number too high! Try again!" item = 0 except ValueError: print "Item number not correct! Try again!" item = 0 try: if item > 0: amount = int(raw_input('Enter quantity of selected item: ')) except ValueError: print "Amount not correct, has to be whole number! Try again!" amount = 0 if item > 0 and amount > 0: add2cart(item, amount) else: print "Please enter item and amount again!\a\n" # added .lower() so user can enter 'No' or 'NO' or 'no' more = raw_input('Want to buy something else (yes/no)? ').lower() # user can enter 'no' or just 'n' if 'n' in more: print "Thank you for your order, here is your purchase detail:" break print '\n', '~'*38 for x in range(len(cart)): item_number = cart[x][0] gem = list_of_gems[item_number][0] price = list_of_gems[item_number][1] quantity = cart[x][1] total_per_item = cart[x][2] print '%4d %8s @ $%0.2f = $%5.2f' % (quantity, gem, price, total_per_item) total += total_per_item print '~'*38 print "\t%18s = $%4.2f" % ('TOTAL', total)
drink her pretty
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.
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
Just a sometimes elusive Python/Tkinter rectangle. Could that be turned into a game?
Click on "Toggle Plain Text" so you can highlight and copy the code to your editor without the line numbers.
python Syntax (Toggle Plain Text)
# click on the red rectangle ... from Tkinter import * import random def create_rect(): chance = random.sample(range(1, 250), 4) print chance # test eg. [72, 206, 116, 166] canvas.create_rectangle(chance, fill="red") def check_rect(event): rect = canvas.find_overlapping(event.x, event.y, event.x, event.y) if rect: # delete old rectangle canvas.delete(rect) # create new rectangle create_rect() root = Tk() root.title("click on red") canvas = Canvas(root, height=250, width=250, bg="yellow") canvas.pack() # create the starting random rectangle create_rect() # respond to left mouse button click canvas.bind("<Button-1>", check_rect) root.mainloop()
Last edited by vegaseat; Mar 1st, 2007 at 4:28 pm. Reason: code=python tag
May 'the Google' be with you!
The code below shows a birthday message on fairly large banner using the Tkinter GUI module.
Now improve the code so each of the letters shows up in a different color following the colorpattern of a rainbow.
python Syntax (Toggle Plain Text)
# a simple banner using Tkinter from Tkinter import * #create the form root = Tk() canvas1 = Canvas(root, height=100, width=600, bg="white") canvas1.pack() str1 = "Happy Birthday Ursula!" x = 20 y = 20 text1 = canvas1.create_text(x, y, anchor=NW, text=str1, font=('times', 32, 'bold'), fill='red') root.mainloop()
Last edited by vegaseat; Mar 1st, 2007 at 4:29 pm. Reason: code=python tag
May 'the Google' be with you!
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:
After the five letters, have the user guess the word. If they get it right, congratulate them. Otherwise, tell them the correct word.
Python Syntax (Toggle Plain Text)
- Say the word is "jelly" and they guessed "l" --ll-
After the five letters, have the user guess the word. If they get it right, congratulate them. Otherwise, tell them the correct word.
•
•
Join Date: Nov 2006
Posts: 1
Reputation:
Solved Threads: 0
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.
btw if someone knows a way to make this smaller email me please
Python Syntax (Toggle Plain Text)
f=[0,1] for i in range(input()-2): f.append(f[-2]+f[-1]) print f
Last edited by vegaseat; Nov 18th, 2006 at 10:49 am. Reason: Fibonacci
![]() |
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: What does "steals" a reference mean?
- Next Thread: wondering some things about lists
| Thread Tools | Search this Thread |
alarm ansi app assignment avogadro backend beginner binary bluetooth character cmd customdialog cx-freeze data decimals dictionary directory dynamic error exe file float format function generator getvalue gnu graphics halp heads homework http ideas images import input ip itunes java leftmouse line linux list lists loop maintain maze millimeter module mouse number numbers output parsing path pointer prime programming progressbar push py2exe pygame python queue random recursion schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh statistics string strings sudokusolver sum text thread threading time tlapse tuple tutorial ubuntu unicode url urllib urllib2 variable variables ventrilo vigenere web webservice wikipedia write wxpython xlib






