•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 370,597 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,026 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser:
Views: 50641 | Replies: 154
![]() |
•
•
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,312
Reputation:
Rep Power: 8
Solved Threads: 169
If you had a way to mark water molucules, and then added 1 drop of
that marked water into the earth's oceans and mixed it well. How many
of the marked molcules of water would you find in each drop of ocean water?
Some helpful information:
Avogadro's number N = 6.023 x 10^23 (6.023e23) molecules/mole
1 mole of water has a volume of 18 ml
Assume that 1 ml water contains 30 drops
Volume of all the earth's oceans is 1.35 billion cubic kilometers
that marked water into the earth's oceans and mixed it well. How many
of the marked molcules of water would you find in each drop of ocean water?
Some helpful information:
Avogadro's number N = 6.023 x 10^23 (6.023e23) molecules/mole
1 mole of water has a volume of 18 ml
Assume that 1 ml water contains 30 drops
Volume of all the earth's oceans is 1.35 billion cubic kilometers
Last edited by vegaseat : Mar 14th, 2008 at 7:58 pm.
May 'the Google' be with you!
You are constructing a robot vehicle that has two tracks like a tank. Each track is driven by a DC motor that can go from full foreward (signal = 1.0) to slower foreward (eg. signal = 0.3) to rest (signal = 0.0) and slow reverse (eg. signal = -0.1) to full reverse (signal = -1.0). To turn, one track is moved slower than the other.
The control is done with a joy stick that has two variable outputs. One is the x-axis (full foreward 1.0 to full reverse -1.0) and y-axis (full left = 1.0 to full right -1.0). Write a Python program that interprets these outputs correctly so the two motors can receive the proper signal for variable speeds foreward, reverse, and left and right turns.
The control is done with a joy stick that has two variable outputs. One is the x-axis (full foreward 1.0 to full reverse -1.0) and y-axis (full left = 1.0 to full right -1.0). Write a Python program that interprets these outputs correctly so the two motors can receive the proper signal for variable speeds foreward, reverse, and left and right turns.
drink her pretty
•
•
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,312
Reputation:
Rep Power: 8
Solved Threads: 169
Tomorrow is Easter Sunday, and it's quite early this year. Use the following Python function to calculate the earliest Easter Sunday for the next 100 years (2008 to 2108) and for the next 1000 years ...
python Syntax (Toggle Plain Text)
def calc_easter(year): """returns the date of Easter Sunday of the given yyyy year""" y = year # golden year - 1 g = y % 19 # offset e = 0 # century c = y/100 # h is (23 - Epact) mod 30 h = (c-c/4-(8*c+13)/25+19*g+15)%30 # number of days from March 21 to Paschal Full Moon i = h-(h/28)*(1-(h/28)*(29/(h+1))*((21-g)/11)) # weekday for Paschal Full Moon (0=Sunday) j = (y+y/4+i+2-c+c/4)%7 # number of days from March 21 to Sunday on or before Paschal Full Moon # p can be from -6 to 28 p = i-j+e d = 1+(p+27+(p+6)/40)%31 m = 3+(p+26)/30 # returns (month, day, year) tuple of Easter Sunday return (m, d, y)
May 'the Google' be with you!
Here is a small dictionary of food items and their calories. The portion amounts vary all over the map. Convert all calories for a 1 oz portion or, if you desire, a 100 gram portion (1 oz = 28.35 grams):
python Syntax (Toggle Plain Text)
# a dictionary of {food_name:[amount, calories], ...} food = { "pastrami": ["2 oz", 170], "meatloaf": ["3 oz", 315], "veal": ["3.5 oz", 190], "beef": ["2 oz", 310], "venison": ["4 oz", 225], "potato": ["8 oz", 100], "spinach": ["8 oz", 45], "tomato": ["8 oz", 45], "egg plant": ["3.5 oz", 25], "cauliflower": ["8 oz", 35], "butter": ["1 oz", 200], "cheddar": ["1 oz", 115], "swiss": ["1 oz", 105], "egg": ["2 oz", 80] }
Never argue with idiots, they'll just bring you down to their level and beat you with their experience.
Using the Tkinter or the wxPython GUI toolkit, design a program that uses sliders to change the RGB values of a sample label's background color and its text (foreground) color in real time. Once you are happy with the colors, allow it to save the rgb values to the clipboard so they can be used in a program.
This Python snippet might be of help:
http://www.daniweb.com/code/snippet457.html
This Python snippet might be of help:
http://www.daniweb.com/code/snippet457.html
Last edited by ZZucker : May 8th, 2008 at 4:23 pm. Reason: ref
Never argue with idiots, they'll just bring you down to their level and beat you with their experience.
Here is a very basic text editor using the wxPython GUI toolkit. Your mission will be to add some features like find, replace, wordcount etc. to it:
python Syntax (Toggle Plain Text)
# the start of a small text editor with file load and save menu # notice that the wx.TextCtrl() surface has already some advanced # features: # you can select text, right click to cut, copy and paste etc. import os import wx # pick unique ID values ID_ABOUT = 101 ID_LOAD = 102 ID_SAVE = 103 ID_EXIT = 110 class MyFrame(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, wx.ID_ANY, title, size = (500, 300)) self.control = wx.TextCtrl(self, 1, style=wx.TE_MULTILINE) # statusBar at the bottom of the window self.CreateStatusBar() # set up the menu filemenu= wx.Menu() filemenu.Append(ID_ABOUT, "&About"," Information about this program") filemenu.Append(ID_LOAD,"File&Load", " Load a text file") filemenu.Append(ID_SAVE,"File&Save", " Save a text file") filemenu.AppendSeparator() filemenu.Append(ID_EXIT,"E&xit"," Terminate the program") # create the menubar menuBar = wx.MenuBar() # adding the "filemenu" to the MenuBar menuBar.Append(filemenu,"&File") # adding the MenuBar to the Frame content self.SetMenuBar(menuBar) # attach the menu-event ID_ABOUT to the method self.OnAbout wx.EVT_MENU(self, ID_ABOUT, self.OnAbout) # attach the menu-event ID_OPEN to the method self.OnOpen wx.EVT_MENU(self, ID_LOAD, self.OnLoad) # attach the menu-event ID_SAVE to the method self.OnSave wx.EVT_MENU(self, ID_SAVE, self.OnSave) # attach the menu-event ID_EXIT to the method self.OnExit wx.EVT_MENU(self, ID_EXIT, self.OnExit) # display the frame self.Show(True) def OnAbout(self, e): """ the about box """ about = wx.MessageDialog( self, " A very simple editor \n" " using the wxPython GUI toolkit", "About Simple Editor", wx.OK) about.ShowModal() about.Destroy() def OnLoad(self, e): """ open a file""" self.dirname = '' dlg = wx.FileDialog(self, "Choose a file to load", self.dirname, "", "*.*", wx.OPEN) if dlg.ShowModal() == wx.ID_OK: self.filename = dlg.GetFilename() self.dirname = dlg.GetDirectory() f = open(os.path.join(self.dirname,self.filename),'r') self.control.SetValue(f.read()) f.close() dlg.Destroy() def OnSave(self, e): """ Save a file""" self.dirname = '' dlg = wx.FileDialog(self, "Choose or create a file to save to", self.dirname, "", "*.*", wx.OPEN) if dlg.ShowModal() == wx.ID_OK: self.filename = dlg.GetFilename() self.dirname = dlg.GetDirectory() f = open(os.path.join(self.dirname,self.filename),'w') self.control.GetValue(f.write()) f.close() dlg.Destroy() def OnExit(self, e): self.Close(True) app = wx.PySimpleApp() frame = MyFrame(None, -1, "A Simple Editor (click on File for menu)") app.MainLoop()
drink her pretty
How about a Noughts and Crosses game with AI so when the computer can it will win and it will block the player from winning if it can.
Try make it so there are difficulty setting ranging from easy to beat to nearly impossible.
If you want you could add a tournament kind of thing by having 'best of three' rounds
Try make it so there are difficulty setting ranging from easy to beat to nearly impossible.
If you want you could add a tournament kind of thing by having 'best of three' rounds
Make it idiot proof and someone will make a better idiot.
Check out my Blog - paulthom12345.blogspot.com
Check out my Blog - paulthom12345.blogspot.com
Some Python riddles. Try to figure out the possible results:
python Syntax (Toggle Plain Text)
print max(max('hello', 'world'))
python Syntax (Toggle Plain Text)
print [1] * 5
python Syntax (Toggle Plain Text)
q = zip(range(3), 'abc') t1, t2 = zip(*q) print q print t1 print t2
I upped my sanitary measures, up yours!
The short Python program below shows you how to create a hot-spot on a frame/window surface using the Tkinter GUI toolkit:
Your project will be to put a picture or map image on the surface, and then create a number of hot-spots. When the mouse pointer gets in range of these hot-spots a descriptive text message could appear. You could also make it different sounds or whatever, use your imagination.
python Syntax (Toggle Plain Text)
# show mouse position as mouse is moved and create a hot-spot import Tkinter as tk root = tk.Tk() def showxy(event): xm = event.x ym = event.y str1 = "mouse at x=%d y=%d" % (xm, ym) root.title(str1) # switch color to red if mouse enters a set location range (hot-spot) x = 100 y = 100 delta = 10 # range around center x,y if abs(xm - x) < delta and abs(ym - y) < delta: frame.config(bg='red') else: frame.config(bg='yellow') frame = tk.Frame(root, bg= 'yellow', width=300, height=200) frame.bind("<Motion>", showxy) frame.pack() root.mainloop()
Last edited by ZZucker : May 28th, 2008 at 4:45 pm.
Never argue with idiots, they'll just bring you down to their level and beat you with their experience.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
- 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: receive bytes streams
- Next Thread: If <not number>?



Linear Mode