944,198 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Unsolved
  • Views: 173446
  • Python RSS
You are currently viewing page 21 of this multi-page discussion thread; Jump to the first page
Oct 16th, 2009
0
Re: Projects for the Beginner
write a program to find the factorial of a number.
Hint: the program can be written in two ways - using a proper algorithm, or using recursion algorithm

P.S sorry in this is already posted in the forum...i didn't read all previous posts
Reputation Points: 20
Solved Threads: 74
Posting Whiz in Training
masterofpuppets is offline Offline
272 posts
since Jul 2009
Oct 30th, 2009
0
Re: Projects for the Beginner
Design a simple text-based calculator program that does all the simple calculations like addition, subtraction, multiplication and division. The program should have a menu and should prompt the user to enter an operation and print the result from that operation. Simple interaction would look like this:

Python Syntax (Toggle Plain Text)
  1. >>>Available operations:
  2. 1. Addition
  3. 2. Subtraction
  4. 3. Multiplication
  5. 4. Division
  6.  
  7. Choose an operation: 1
  8. Enter first number: 2
  9. Enter second number: 3
  10. 2 + 3 = 5
  11.  
  12. Available operations:
  13. ....
  14. ....
Hint: divide the program into separate functions for each operation and for the menu as well

More advances stuff:
add the option conversion from binary to decimal and vice-versa
Last edited by masterofpuppets; Oct 30th, 2009 at 11:21 am.
Reputation Points: 20
Solved Threads: 74
Posting Whiz in Training
masterofpuppets is offline Offline
272 posts
since Jul 2009
Oct 31st, 2009
1
Re: Projects for the Beginner
Here is a simple number project:

Prime numbers are positive integer numbers that are only divisible by itself or one. For example 2, 3, 5, 7, 11, 13, 17, are prime numbers, by convention 1 is not a prime number.

Palindrome numbers are numbers in which the decimal digits are the same read left to right as they are read right to left. For example 77, 131, 1441.

Your mission is to write a script that determines and prints all palindrome prime numbers less than 100000. Exclude the simple stuff like one digit numbers.
Reputation Points: 961
Solved Threads: 211
Nearly a Posting Maven
sneekula is offline Offline
2,413 posts
since Oct 2006
Nov 1st, 2009
-1
Re: Projects for the Beginner
Write a python program which will take DNA map of parents and childs as input and determine whether the child belong to the parent or not

Editor: Does anybody notice disgruntled C++ sarcasm?
Last edited by vegaseat; Apr 22nd, 2011 at 11:43 am. Reason: beginner's note
Reputation Points: 769
Solved Threads: 128
Banned
ithelp is offline Offline
1,910 posts
since May 2006
Nov 1st, 2009
0
Re: Projects for the Beginner
This Tinter GUI toolkit program draws a rather ugly stick man ...
python Syntax (Toggle Plain Text)
  1. # exploring Tkinter's canvas drawing surface
  2. # draw lines and ovals to form a stick man
  3. # info at http://effbot.org/tkinterbook/canvas.htm
  4.  
  5. try:
  6. # Python2
  7. import Tkinter as tk
  8. except ImportError:
  9. # Python3
  10. import tkinter as tk
  11.  
  12. def body(w, h):
  13. """draw the oval for the body"""
  14. # an oval is drawn within a given rectangle
  15. # (x1, y1, x2, y2) upper left and lower right corner coordinates
  16. # of the rectangle the ellipse is bound by
  17. # calculate coordinates relative to width w and height h
  18. rect = (w//2-80, h//2-150, w//2+80, h//2+80)
  19. canvas.create_oval(rect, fill='red')
  20.  
  21. def head(w, h):
  22. """draw the oval/circle for the head"""
  23. # if the bounding rectangle is a square a circle is drawn
  24. rect = (w//2-40, h//2-230, w//2+40, h//2-150)
  25. canvas.create_oval(rect, fill='red')
  26.  
  27. def arms(w, h):
  28. """draw lines for right and left arm"""
  29. # draw line from coordinate points x1, y1 to x, y2
  30. # left arm
  31. canvas.create_line(w//2-66, h//2-100, w//2-166, h//2-50)
  32. # right arm
  33. canvas.create_line(w//2+66, h//2-100, w//2+166, h//2-50)
  34.  
  35. def legs(w, h):
  36. """draw lines for right and left legs"""
  37. # draw line from coordinate points x1, y1 to x, y2
  38. # left leg
  39. canvas.create_line(w//2-55, h//2+50, w//2-76, h//2+190)
  40. # right leg
  41. canvas.create_line(w//2+55, h//2+50, w//2+76, h//2+190)
  42.  
  43.  
  44. # create the main window
  45. root = tk.Tk()
  46. root.title("Fred Stickman")
  47.  
  48. # create the drawing canvas
  49. w = 400
  50. h = 500
  51. canvas = tk.Canvas(root, width=w, height=h, bg='white')
  52. canvas.pack()
  53.  
  54. body(w, h)
  55. head(w, h)
  56. arms(w, h)
  57. legs(w, h)
  58.  
  59. # start the GUI event loop
  60. root.mainloop()
Should you be interested, experiment with the drawing and make Fred Stickman look more like a movie star.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Nov 8th, 2009
0
Re: Projects for the Beginner
Create a test directory on your hard drive, copy some files and other directories into it. Now explore Python's file management functions and do the following:
1) list all the files in a given directory
2) list all the files in a given directory and its sub directories
3) list all the files with a given extension
4) copy files from one directory into another directory
5) total up all the file sizes in a given directory
6) find the largest or smallest file in a directory
7) find all the files past a certain cutoff date
8) search all the text files for a given word or sentence
9) change file names and creation dates
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Nov 21st, 2009
0
Re: Projects for the Beginner
1) Write a handy tool like a notes program (you must learn to handle files, strings and GUI)

2) Write a 'program in need' like an automated Gentoo portage updater (I'm making my own, and it's not quite easy, since I support mailing reports, and other portage related tools upgrading like layman, eix or similar)

3) Get an already made program and try to do your own implementation without watching the source code (this is a bit advanced) for example ¿anyone remembers the "Blade: The Edge of Darkness" game? It was done on python.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pizte is offline Offline
3 posts
since Nov 2009
Nov 24th, 2009
0
Re: Projects for the Beginner
If you feel confidence enough, write Eliza program
Reputation Points: 462
Solved Threads: 392
Senior Poster
evstevemd is offline Offline
3,681 posts
since Jun 2007
Nov 28th, 2009
0
Re: Projects for the Beginner
A morse code translator program.
Design the program so that it can translate words or sentences to morse-code. Then extend it so it is able to translate from morse-code. Just google "morse code" to find all the symbols and syntax
Reputation Points: 20
Solved Threads: 74
Posting Whiz in Training
masterofpuppets is offline Offline
272 posts
since Jul 2009
Dec 28th, 2009
1
Re: Projects for the Beginner
Did you know you could do that with the module os?
Python Syntax (Toggle Plain Text)
  1. # using Python module os to create random values
  2.  
  3. import os
  4.  
  5. n = 35
  6. # returns a string of n random bytes
  7. random_bytes = os.urandom(n)
  8. # some bytes may not be printable
  9. # so create a string of all the printable bytes
  10. random_str = ""
  11. for byt in random_bytes:
  12. # select ascii printable bytes/characters
  13. if 32 < ord(byt) < 127:
  14. random_str += byt
  15. print(random_str)
  16.  
  17. for k in range(10):
  18. # random integer from 0 to 255
  19. random_integer = ord(os.urandom(1))
  20. print(random_integer)
Go through all the Python module os functions and write an example code for each.
Moderator
Reputation Points: 1333
Solved Threads: 1404
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Message:
Previous Thread in Python Forum Timeline: For loop, for creating buttons
Next Thread in Python Forum Timeline: How to execute a command with arguments





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC