4,305 Posted Topics

Member Avatar for Garee

You want to keep your card symbols simple and unique to be able to evaluate the hand ... [code]suit_str = "CDHS" rank_str = "23456789TJQKA" deck = [rank+suit for suit in suit_str for rank in rank_str] print(deck) """my output (made pretty) --> [ '2C', '3C', '4C', '5C', '6C', '7C', '8C', '9C', …

Member Avatar for vegaseat
0
346
Member Avatar for sanchitgarg

A time based random number generator will only work if called once, or uses the random time between a user input event. The function time.time() only updates 18.2 times per second, too slow if you request several random numbers quickly.

Member Avatar for sanchitgarg
0
9K
Member Avatar for denniskhor

Generally module md5 is used to encrypt strings/texts like passwords by making a unique check sum of the string. Once encrypted you cannot decrypt the resulting check sum back to the original string. The only way you can find out its contents is to encrypt another string and compare the …

Member Avatar for vansoking
0
1K
Member Avatar for ihatehippies

We wouldn't have this problem if Windows machines would ship with Python installed. The real problem is that MS wants to make money with their old VB interpreter.

Member Avatar for vegaseat
0
110
Member Avatar for Ancient Dragon
Member Avatar for bobfromphilly
6
200
Member Avatar for xm1014

Similar to Gribouillis' code, but uses lambda as a helper function ... [code=python]# sort a more complex combination of lists/tuples: mylist = [ (1, ['a', '3.1', 'ad']), (2, ['b', '4.0', 'bd']), (3, ['c', '2.5', 'cd']), ] # sort by item at index [1][1] of each tuple # using a helper …

Member Avatar for vegaseat
0
444
Member Avatar for pyprog

This might be a little easier to understand for a beginner (thanks to pythopian) ... [code]# parse text data into a dictionary using # split at newline and split at space def parse2dict(text): data_dict = {} for line in text.split('\n'): if line: key, val = line.split() data_dict.setdefault(key, []).append(val) return data_dict …

Member Avatar for pythopian
0
1K
Member Avatar for pyguy420

This might be easier to understand ... [code]if player[0] not in 'rps': print "incorrect choice entered" [/code]

Member Avatar for vegaseat
0
83
Member Avatar for rasizzle

As you most likely found out, there are a number of ways to do this. You picked a good one. There was also a snippet at: [url]http://www.daniweb.com/code/snippet237089.html[/url]

Member Avatar for vegaseat
0
121
Member Avatar for vegaseat

A function that takes a string and returns the number of words in the string. An example of using pointers in Pascal.

Member Avatar for BitFarmer
0
2K
Member Avatar for CurtisEClark

[QUOTE=CurtisEClark;1042345][CODE]import random import pygame w = 640 h = 480 n = random.randrange(6) x = open("shapes.txt") z = x.readlines()[n] screen = pygame.display.set_mode((w, h)) if z == "circle": pygame.draw.circle(screen, (random.randrange(255), random.randrange(255), random.randrange(255)), (random.randrange(640), random.randrange(480)), 100 ) elif z == "line": pygame.draw.line(screen, (random.randrange(255), random.randrange(255), random.randrange(255)), (random.randrange(640), random.randrange(480)), 100 ) elif z == …

Member Avatar for CurtisEClark
0
491
Member Avatar for Yeen

You can simply use this little test ... [code]int_rounds = 3 win = 0 loss = 0 print(int_rounds > max(win, loss)) # True win = 0 loss = 0 print(int_rounds > win or int_rounds > loss) # True win = 0 loss = 0 print(int_rounds > win and int_rounds > …

Member Avatar for vegaseat
0
306
Member Avatar for mitsuevo

A Python dictionary is an efficient way to store data and has very fast lookup speeds ... [code]# in Python you could use a dictionary key:val pair # where the key is the integer index and val is the float # if you just want to store values at an …

Member Avatar for mitsuevo
0
10K
Member Avatar for pyprog

I usually whip up a little test program. Here you use the length of your columns list to avoid problems ... [code]# possible test data data = """\ a,z,1 b,y c,x,1 d,w,1 e,v f,u""" fname = "something.txt" # write test data file ... fout = open(fname, "w") fout.write(data) fout.close() def …

Member Avatar for pythopian
0
132
Member Avatar for saikeraku

Actually, if you temporarily flip to [B]Reply[/B] with quote in the OP post you find out the request was for: [code] H e l l o W o r l d [/code] That is 2 spaces between 'o' and 'W', DaniWeb swallowed up the extra space since it was not …

Member Avatar for pythopian
0
127
Member Avatar for EAnder

How would you define AI? Some folks say that ELIZA is an example of AI: [url]http://www.manifestation.com/neurotoys/eliza.php3[/url]

Member Avatar for lrh9
0
157
Member Avatar for Chromana

Use numpy shape ... [code]import numpy as np # create a 3 by 5 array of integer zeroes z = np.zeros([3, 5], int) print( z ) """ [[0 0 0 0 0] [0 0 0 0 0] [0 0 0 0 0]] """ # check the shape print( "shape --> …

Member Avatar for Chromana
0
306
Member Avatar for jaison2

You can pull a few fixed things out of the drawEye() function and use parameters, but radius makes no sense since it changes within the function ... [code]from graphics import * def drawCircle(win, centre, radius, colour): circle = Circle(centre, radius) circle.setFill(colour) circle.setWidth(2) circle.draw(win) def drawEye(win, centre): drawCircle(win, centre, 40, "white") …

Member Avatar for vegaseat
0
321
Member Avatar for ljvasil

Why don't you simply separate your class Stack out and send it through some simple tests to figure out the errors? Looks like pop() should return something.

Member Avatar for vegaseat
0
619
Member Avatar for pyprog

This all has been solved in thread: [url]http://www.daniweb.com/forums/thread237012.html[/url]

Member Avatar for vegaseat
0
269
Member Avatar for vegaseat

Python can use its COM support and the OCX of the WindowsMediaPlayer to play mp3 music files. Make sure that your Python installation has the win32com folder. Check [url]http://starship.python.net/crew/mhammond/win32/Downloads.html[/url] for the latest win32com support. [COLOR="Red"]This code relies on file WMPlayer.OCX which MS has removed on newer versions of Windows. See …

Member Avatar for vegaseat
1
2K
Member Avatar for TheManual

Or you can do it this way ... [code=python]# these are the accepted characters in the input string accepted = '0123456789dr' while True: mystr = raw_input("Enter data (allowed are integers and 'dr'): ") if all(x in accepted for x in mystr): break print("unaccepted characters in input, try again") print(mystr) # …

Member Avatar for vegaseat
0
124
Member Avatar for pyprog

[QUOTE=pyprog;1040831]Assume I have a file of the following format: a,1 b,2 c,3 d,4 Here is my code: [CODE] def junk(f): d1 = {} d2 = {} for line in f: columns = line.split(":") letters = columns[1] numbers = columns[2] d1[letters] = numbers d2[numbers] = letters return (d1, d2) def something(): …

Member Avatar for vegaseat
0
327
Member Avatar for gangster88

When you post a question like that, give as much pertinent information as you can. You needed to tell us right from the start that you are using the Zelle module graphics. Also, read the code that folks respond with and check it against the errors in your code. I …

Member Avatar for gangster88
0
177
Member Avatar for SpectateSwamp
Member Avatar for Kruptein
Member Avatar for Kruptein
-1
167
Member Avatar for nevets04

[QUOTE=nevets04;1038393]Solved: [code] List = [] for x in xrange(5): List.append(raw_input("")) [/code][/QUOTE] Wow, I would have never guessed that from your original question. Hint, variable names starting with a capital letter are by convention used for class names.

Member Avatar for nevets04
0
184
Member Avatar for nevets04

[QUOTE=nevets04;1039439]I know Remembering secure passwords is difficult. So I made this. [code] import random, os a= ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','1','2','3','4','5','6','7','8','9','{',':','>','?','}','|','!','@','#','$','%','^','&','*','(',')','-','+'] z = int(raw_input("How many words in your password?: ")) os.system("clear") List = [] for x in xrange(z): List.append(random.choice(a)) print "".join(List) print "1) Yes" print "2) No" b = int(raw_input("Would you like to save …

Member Avatar for sneekula
0
165
Member Avatar for parsifal67

You should really start a new thread of your own! The string function find() can find a subtext within a larger text, as will re.findall(). The advantage of find() is that it will give you the location in the form of an index.

Member Avatar for mitsuevo
0
257
Member Avatar for Kruptein

I hope you have luck finding someone who actually uses pygtk. I run on a Windows platform and pygtk is a bear to install.

Member Avatar for Kruptein
0
137
Member Avatar for Judgment

[QUOTE=Mathhax0r;1039559]The first two only require one liners of logic, so here: [CODE]n = int(raw_input("How many squares? ")) squares = [x*x for x in range(1,n+1)] print square[/CODE] [CODE]def even_only(argList): return filter(lambda m: m%2==0, argList)[/CODE] As for the pig latin, you'll need to break the sentence down into words with split, do …

Member Avatar for vegaseat
-1
151
Member Avatar for ChaseRLewis

For programs like this, recursion is not a very good idea. Calling a function, even itself, is one of the slower things in programming because of the stack control. You will find that in the faster prime algorithms repeated function calls are absent. Here is an example of one of …

Member Avatar for vegaseat
0
220
Member Avatar for krishna_sicsr

Take a looky at something like this ... [code]data = """\ ------------------------------------ ----------- --------- ------------------------------------ ----------------------------- ------- PRODUCT KIT TYPE STATE MAINTENANCE REFERENCED BY ------------------------------------ ----------- --------- ------------------------------------ ----------------------------- ------- HP I64VMS ACUXE V6.40-11P09A Full LP Installed HP I64VMS AVAIL_MAN_BASE V8.3-1H1 Full LP Installed HP I64VMS OPENVMS V8.3-1H1 HP I64VMS …

Member Avatar for vegaseat
0
168
Member Avatar for P00dle

If you read a binary as a text file (mode='r'), you have to be aware that the binary data can inadvertently contain an EOF (End Of File) marker early on, at which point the read would stop. Using a binary read (mode='rb') will prevent this. Here is a simple way …

Member Avatar for P00dle
0
163
Member Avatar for PixelHead777

I think you should learn Lisp to get familiar with parenthesis. Yes, you are using too many of those in your Python code. You can study up in the precedence of mathematical operations to remove a fair number of them.

Member Avatar for woooee
0
229
Member Avatar for efecto

You can use one of the built-in string functions ... [code]n = 2 digits = 3 ns = str(n).rjust(digits, '0') print(ns) # 002 [/code]

Member Avatar for vegaseat
0
146
Member Avatar for jaison2

One eye has to be positioned center_left, the other center_right ... [code]from graphics import * import math def drawCircle(win, centre, radius, colour): circle = Circle(centre, radius) circle.setFill(colour) circle.setWidth(2) circle.draw(win) def drawTarget(): win = GraphWin() centre_left = Point(50,100) centre_right = Point(150,100) drawCircle(win, centre_left, 40, "white") drawCircle(win, centre_left, 20, "blue") drawCircle(win, centre_left, …

Member Avatar for vegaseat
0
193
Member Avatar for Felicidas

This problem really asks for the use of a dictionary object ... [code=python]# typical test data data = """\ 1 20 2 56 3 42 4 53 5 90 6 33 """ fname = 'mytest123.txt' # write test data to a file fout = open(fname, "w") fout.write(data) fout.close() # read …

Member Avatar for vegaseat
0
197
Member Avatar for i are smart

What Gribouillis means is run this code and post the output here on DaniWeb ... [code=python]# show the system path for Python ( PYTHONPATH ) import sys print( sys.path ) [/code]You need to run this with the version of Python you are interested in. Also you cannot permanently set PYTHONPATH …

Member Avatar for vegaseat
0
688
Member Avatar for jaison2

jaison2, [B]range(drawBlock)[/B] in your code does not make any sense, since range() expects an integer value. In your loop you want something like this ... [code]for row in range(height): # multiplier will give width number of '#' characters print '#' * width [/code]

Member Avatar for vegaseat
0
98
Member Avatar for AutoPython

I want to encourage posters to give us the version of Python they are using. Otherwise the rest of us have to assume and ask. Python25 for instance allows you to use the print statement or the print() function. So using the fact that print() was used is not necessarily …

Member Avatar for jlm699
0
175
Member Avatar for nevets04

Remove all the silly [B]os.system("clear")[/B], they are not needed and work on one specific OS only, then it will work ... [code]#Credits: #Nevets04 #Fallen #Uber1337 #Farout #import os List = [] z = int(raw_input("How many words in your list?: ")) #os.system("clear") for x in xrange(z): List.append(raw_input("Enter word: ")) List.sort()#,os.system("clear") print …

Member Avatar for vegaseat
0
112
Member Avatar for tdeck

Take a look at the final lines of this code snippet: [url]http://www.daniweb.com/code/snippet216747.html[/url]

Member Avatar for jlm699
0
328
Member Avatar for logon84

So the next question is: Is it you against the computer, or you against another human?

Member Avatar for manathisbest
-2
172
Member Avatar for sneekula
Member Avatar for vegaseat
1
495
Member Avatar for kisan

Let's hope this is not homework and the OP had a chance to learn something. In a true palindrome test you also need to remove everything but the case adjusted letters. "Madam in Eden I'm Adam" is a palindrome.

Member Avatar for Gribouillis
-1
193
Member Avatar for Kolz

You can easily explore it yourself ... [code]# exploring Python's file random access text = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' fname = 'test103.txt' # create a test file fout = open(fname, "w") fout.write(text) fout.close() # open the test file for reading fin = open(fname, "r") # file positions are zero based # tell the …

Member Avatar for vegaseat
0
209
Member Avatar for saikeraku

In your second problem in function even_list the for loop should iterate through the list you are giving the function. If you find an item in that list that is even, then you have to append it to the list you call lista. If you are trouble shooting, it always …

Member Avatar for katharnakh
0
111
Member Avatar for ihatehippies
Member Avatar for pyprog

The more common approach would be to use append() ... [code=python]for line in f: columns = line.split(",") letters = columns[ 0 ] list1.append(letters) [/code]I think it is less mistake prone. I also want to point out, that should you want to read the second column (the end of each line), …

Member Avatar for snippsat
0
325

The End.