Forum: Python 1 Day Ago |
| Replies: 2 Views: 104 class Critter(object):
"""A virtual pet"""
def __init__(self, name, hunger = 0, boredom = 0):
self.name = name
self.hunger = hunger
self.boredom = boredom
... |
Forum: Python 2 Days Ago |
| Replies: 10 Views: 256 Is it not better to make one function like this to add 2 number.
def add_number():
n = raw_input('Enter number to add format (2+2)')
num1, num2 = n.split('+')
my_sum = int(num1) +... |
Forum: Python 2 Days Ago |
| Replies: 10 Views: 256 Look at this here two way to work with function.
Maybe you get some idèe on how to solve your +*-/ with function and a menu.
One function i just return and do calulation in main.
They other... |
Forum: Python 2 Days Ago |
| Replies: 10 Views: 256 Two classes with 1 attributt(variable) in each,is not a normal OO design.
Your program work,but for me this is not a good way to code.
Some problem.
Menu should come first so user now what this... |
Forum: Python 3 Days Ago |
| Replies: 4 Views: 17,120 Animals is always fun to make with oop design in mind.
Here you se __call___ used like this cow('gras')
This fill the the empty list(stomach)
class Animal(object):
def __init__(self, name,... |
Forum: Python 3 Days Ago |
| Replies: 6 Views: 145 A more normal way to use __int__ (constructor) in a python class.
And just some point that a class is storeing variables in a dictionary.
from math import sqrt
class ageName(object):
... |
Forum: Python 3 Days Ago |
| Replies: 3 Views: 196 I have are hard time understand why instructors use outdatet module like graphics.
It has to be much better to learn student basic Tkinter(graphical user interface) or another GUI toolkit.
That... |
Forum: Python 3 Days Ago |
| Replies: 4 Views: 149 Free books.
http://www.swaroopch.com/notes/Python
http://www.diveintopython.org/
http://diveintopython3.org/
http://homepage.mac.com/s_lott/books/python.html... |
Forum: Python 4 Days Ago |
| Replies: 10 Views: 272 Tkinter is the build in gui(Graphical user interface) of python.
There are many other good gui toolkit like wxpython - PyQt -PyGTK.
No Tkinter or any other gui toolkit is to display our python... |
Forum: Python 5 Days Ago |
| Replies: 7 Views: 279 Global should not be used at all,it`s no good at all.
Learn to code without it.
Here one way to do what you want.
import random
def main(max_guess):
num = random.randrange(1,... |
Forum: Python 6 Days Ago |
| Replies: 19 Views: 499 Try pyscripter has a lot off useful feature and off course auto-indent.
http://code.google.com/p/pyscripter/ |
Forum: Python 6 Days Ago |
| Replies: 9 Views: 309 The example is simple and you shoul try to understand it.
Break it down and ask question.
def get_data():
"""get the data from the user, from a file, or hard coded"""
mydata = [1, 2, 3,... |
Forum: Python 8 Days Ago |
| Replies: 15 Views: 433 Maybe,but i wont speend any tïme at all on an outdatet module like graphics.py.
It was just made as an intro to graphic,you much forget this module if you want to make something ourself.
Look at... |
Forum: Python 8 Days Ago |
| Replies: 15 Views: 433 You should not speend much time on outdate mouduls like graphics.py.
Think it was written in 2005 by John M. Zelle as and easy intro to graphics for beginner.
The only way to do this is to learn... |
Forum: Python 11 Days Ago |
| Replies: 14 Views: 449 Do you think we can se your code based on output print screen?
If you want help you post your code or the part you think cause the problem. |
Forum: Python 11 Days Ago |
| Replies: 9 Views: 391 You can use what ide editor you want, whish gui toolkit you use dos have little impact.
Pyscipter is good.
http://code.google.com/p/pyscripter/
I use komodo ide,and pyscripter for python 3.x... |
Forum: Python 11 Days Ago |
| Replies: 14 Views: 449 Dictionary values are accessed by their key. To allow for high speed key searches, the keys are in a hash order. So a dictionary sorted alphabetically by it's keys would make no sense and would... |
Forum: Python 11 Days Ago |
| Replies: 10 Views: 370 >>> import webbrowser
>>> dir(webbrowser)
['BackgroundBrowser', 'BaseBrowser', 'Elinks', 'Error', 'Galeon', 'GenericBrowser', 'Grail', 'Konqueror', 'Mozilla', 'Netscape', 'Opera', 'UnixBrowser',... |
Forum: Python 12 Days Ago |
| Replies: 10 Views: 493 Kind off help whit some clear messages.
>>> we_dot_do_homework_if_no_effort_is_shown = 2
>>> 1 % we_dot_do_homework_if_no_effort_is_shown
1
>>> 2 % we_dot_do_homework_if_no_effort_is_shown
0... |
Forum: Python 14 Days Ago |
| Replies: 2 Views: 235 Have you tryed som yourself,and mayby post some code.
Can take a little about this but next time dont expext to get help if you dont but some effort in to this.
>>> lst = ['bunnies', 'apples',... |
Forum: Python 15 Days Ago |
| Replies: 3 Views: 214 There is no goto int python and thank god for that.
In python you use loop/ function calls or and OOP design with classes to get where you whant in your code
This depend of how you design your... |
Forum: Python 16 Days Ago |
| Replies: 2 Views: 203 There are several problems.
if number == '1' : #use '1'because input in python 3 return a string.
Then you come to this meny.
print ('1. Operating expense')
print ('2. Payroll expense')... |
Forum: Python 17 Days Ago |
| Replies: 8 Views: 292 As Mathhax0r take upp your code is really not god at all it`s a big mess.
I think helping you now is difficult because of your code design.
Never use global variabels like this, or at all.
The... |
Forum: Python 17 Days Ago |
| Replies: 5 Views: 271 Vegaseat has pretty much given you the answer.
You dont say that code dos not work and nothing more.
Then is not possibly to help you,post your code and then you say it will not work or try to... |
Forum: Python 17 Days Ago |
| Replies: 2 Views: 211 If you what this result is better to iterate over the list and append the result to a new list.
L = [ 0 , 2, 1 , -1 , -1 , -1, -1 ]
new_list = []
for item in L:
if item >= 0:
... |
Forum: Python 17 Days Ago |
| Replies: 4 Views: 227 Tkinter has change import name in python 3.
Put this first then tkinter import correct for python 2.x and 3.x
try:
# for Python2
import Tkinter as tk
except ImportError:
# for... |
Forum: Python 18 Days Ago |
| Replies: 2 Views: 238 Here is class example have i tryed to explain som basic thing about the making of a class and how thing work.
class SimpleClass(object):
'''
Doc string info about class
* SimpleClass... |
Forum: Python 18 Days Ago |
| Replies: 4 Views: 291 You can do it like this.
def getValidNum(min, max):
print ('Enter a value between %d and %d | 0 to quit' % (min, max))
while True:
try:
num = input('>')
... |
Forum: Python 19 Days Ago |
| Replies: 11 Views: 456 You can use a dictionary like this.
Now user can only input 123 to get past meny, anything else give error message and loop back.
Yes more easy for user to just type a number than write... |
Forum: Python 19 Days Ago |
| Replies: 4 Views: 292 Newer.
http://rgruet.free.fr/PQR25/PQR2.5.html
http://rgruet.free.fr/PQR26/PQR2.6.html |
Forum: Python 19 Days Ago |
| Replies: 11 Views: 456 Ahh when user input is should be like this off course.
comp = random.choice(choices) #comp
human = choice #human |
Forum: Python 19 Days Ago |
| Replies: 11 Views: 456 Ok make it simpler.
import random
choices = ['rock', 'paper', 'scissors']
while True:
choice = input("please enter your choice(rock-scissors-paper): ")
if choice in choices:
... |
Forum: Python 19 Days Ago |
| Replies: 9 Views: 307 New style class python 2.2--> you should use class(object):
Old style pre python 2.2 class:
So object is a build in,let`s test it.
IDLE 2.6.2
>>> object
<type 'object'>
>>>
For more... |
Forum: Python 20 Days Ago |
| Replies: 5 Views: 256 You know that this code is for python 3.x?
For python 2.x
n = input('Enter an interger >= 0: ')
fact = 1
for i in range(2,n+1):
fact = fact*i
print n, 'factorial is', fact
print 'The... |
Forum: Python 20 Days Ago |
| Replies: 11 Views: 456 Yes you use python 3.x i see(when you post make a note that you use python 3.x)
Python 3 has no raw_input only input.
return choice you can not use return if you dont make a function.
So this... |
Forum: Python 20 Days Ago |
| Replies: 11 Views: 456 import random
def rockPaperScissors():
#choice = raw_input("please enter your choice: ") #I take away this to make a point
computerIndex = random.randint(0,2)
if computerIndex ==... |
Forum: Python 20 Days Ago |
| Replies: 15 Views: 533 There is no point in just get it to work,what to learn by that?
That bad design is ok.
here you make board global.
global board
This wont draw 1 X as you want,you known why?... |
Forum: Python 20 Days Ago |
| Replies: 15 Views: 533 Dont use global variables.
Any name (variable) defined inside a function is local to that function,and should always stay that way.
If you need access to a function's local variables outside that... |
Forum: Python 21 Days Ago |
| Replies: 12 Views: 326 Yes as it should do,is should not be so hard to understand.
<= 10 means that less than 10 or equal to 10 it will add 1.50.
Then off course if you input is 10 it will add 1.50 and print 11.50.
< 10... |
Forum: Python 21 Days Ago |
| Replies: 5 Views: 279 >>> suits = ['diamonds', 'clubs', 'hearts', 'spades']
>>> rank = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King']
>>> # This is what we need to make a hole deck
>>> # Now we loop trough... |