hondros 25 Junior Poster

Um. People, it is very tough to create a fully functional web browser such as Firefox, IE, Chrome, Safari, etc. If you want to do something simple, how about using Python and a GUI toolkit to retrieve a website, then display it. It'd just have a simple address bar, and you type in the address, then it grabs the website's html, from connecting to port 80 of the ip address, and displays it. But it'd be very tough to make a fully functional browser all by yourself

hondros 25 Junior Poster

Uh. Wow spam on that first comment. Plus bad grammar. >>
I think that taxing internet services are stupid. It'll raise the prices of all the internet products, and that's not needed right now. It'll just make things worse

hondros 25 Junior Poster

This is understandable. My girlfriend loves to have sexual RP's with a lot of people online. It doesn't bother me at all. I'm not good at it for her, and it's not like I should control what she does online where it doesn't matter. :/ It's stupid to take it so seriously

hondros 25 Junior Poster

xD Nice. I am in the middle of creating a text-based RPG all by myself. I'm thinking it'll take at least a month. Right now I have all the equipment done, and the character's format. Then that's how I save the character. I was taking a look at it, and it'd be somewhat easy to hack it, so I'm thinking about implementing my encryption program into my RPG, so if you change a number, it screws it up. Oh, it's matrix encoding, btw. I can send you the script if you want to see it

hondros 25 Junior Poster

Okay, so here is how i hear it in my head.
Files 1-5:
hd1
hd2
hd3
hd4
hd5
And you want to be able to save everything from file example.doc
And the amount of files can vary. Here's a simple script that askes how many files for it:

# Open the original file to be written
f = open("example.doc", "r")
data = f.read
f.close()
# Ask the user how many files to be written
to_write = int(raw_input("How many files to write? "))
# Perform a loop to write the data to each file
for x in range(0, to_write):
    file = "hd" + str(x) + ".doc"
    # Try to open a file and read it. If it can't open it, it creates a file
    try:
         f = open(file, "r")
         to_file = f.read()
         f.close()
         f = open(file, "w")
         f.write(to_file)
   except:
          f = open(file, "w")
   # Now write to the file all data
   f.write(data)
# That was the end

Hopefully this code works, I have not tried it out. Take a look and see if you can tell what exactly it's doing. Good luck

hondros 25 Junior Poster

Hey, someone thought my idea would come in handy later! *hi fives* But yeah, that'll come in handy for saving, say game saves, records, etc. And if you want to get really fancy, you can just append it to the end of your file. And make sure you specify it's a .exe if you compile it. Then people won't know how to get it xD. I''m sure they'd figure out, but oh well

hondros 25 Junior Poster

Did you install py2exe correctly?
Also, you might want to change "console" to "window". That will make it so no console window opens up, just the game.
Also, I think I remember reading somewhere that pygame isn't compatible with py2exe, might want to google that.

EDIT:
Found this:
http://www.moviepartners.com/blog/2009/03/20/making-py2exe-play-nice-with-pygame/

hondros 25 Junior Poster

Don't know if it's been suggested, but if you're into wanting to make video games, try to create a text version of Battleship, Tic-Tac-Toe, or any other game you can think of. Then, create an AI to play with you. And make it really good, and hard to beat. It's harder than it sounds.

hondros 25 Junior Poster

:D Thanks, that sure does shorten a lot of code. And thank you for the links, that helps me a lot. So right now I am trying to create the AI based off the X(3)X(3) pattern. any tips on how to save space for creating the list of co-ordinates? I'll think about a way first though. I won't mark this thread as solved until I get my program finished, and I'll come back in and update with how it's coming along. And I know there are plenty of battleship programs already made >>

hondros 25 Junior Poster

The only way I can think of, is to save a file, perhaps named win.cfg. This file will contain how many points a person has. I'll explain the code using comments:

# First, check to see if the file exists
# If not, create the file, and open it again
while True:
    try:
        f = open("win.cfg", "r")
        break
    except:
        f = open("win.cfg", "w")
        f.write(0)
        f.close

# Now, read the number inside the file
PLAYER_TOTAL = f.read()
f.close()

# The game
import random

def gameIntro():
    print('''This is a dice roll game. Dice are rolled, and you recieve money
if you are equal to the total. Are you ready?''')
    print('Yes or no?')
    return input().lower().startswith('y')

def gamePlay():
    # Take this out
    #PLAYER_TOTAL = 0
    dieRoll = random.randint(1, 6)
    dieRoll1 = random.randint(1, 6)
    print()
    print('Guess a number from 1 to 12')
    playerGuess = int(input())
    diceTotal = dieRoll + dieRoll1
    if playerGuess == diceTotal:
        print('Woo! You got it! Plus $5 for you!')
        PLAYER_TOTAL += 5
        # This is where we write to the file
        f = open("win.cfg", "w")
        f.write(PLAYER_TOTAL)
        f.close()
        print()
        print('You have ' + str(PLAYER_TOTAL))
    else:
        print('Sorry you didn\'t match the dice roll. Try again?')
        input().lower().startswith('y')
        while False:
            print('Goodbye!')
            break

gameIntro()
while True:
    gamePlay()

Now, this is just a basic write to file, and load it. Very easy for someone to hack it, and make it seem like they got a higher score. That's where you can use pickle. Just import pickle , then pickle.dump(PLAYER_TOTAL, f) I think that's how the variables go, …

hondros 25 Junior Poster

Okay, so I am creating a battleship game, I posted a thread here earlier to figure out how to place the ships, but know I'm back, because I am curious as to how I should program the AI for it. Here's my base code now, and I'll explain how the board is used.

# import needed modules
import random

# _ Shows a spot not fired at yet
# + Shows your ship placement
# X Shows a hit ship
# O Shows a miss
# 

# These are the boards
# This is the board the user uses for their ships,
# and the computer hits this board, so only one is needed
user_board = []
# This is the board the computer puts their ships on,
# and is not shown to the user
comp_board = []
# This board is empty at first, and the user sees it
comp_boardu = []
for row in range(10):
    user_board.append(['_']*10)
    comp_board.append(['_']*10)
    comp_boardu.append(['_']*10)

# This is the format of the board
# Don't ask why the variable is called comp_board
# It's a long story of experimenting, I can change it,
# but it'd be too time consuming
def show(comp_board):
    print """_____________________________________________
|===|_0_|_1_|_2_|_3_|_4_|_5_|_6_|_7_|_8_|_9_|
|_A_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|""" %(comp_board[0][0], comp_board[0][1], comp_board[0][2], comp_board[0][3], comp_board[0][4], comp_board[0][5], comp_board[0][6], comp_board[0][7], comp_board[0][8], comp_board[0][9])
    print "|_B_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|" %(comp_board[1][0], comp_board[1][1], comp_board[1][2], comp_board[1][3], comp_board[1][4], comp_board[1][5], comp_board[1][6], comp_board[1][7], comp_board[1][8], comp_board[1][9])
    print "|_C_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|" %(comp_board[2][0], comp_board[2][1], comp_board[2][2], comp_board[2][3], comp_board[2][4], comp_board[2][5], comp_board[2][6], comp_board[2][7], comp_board[2][8], comp_board[2][9])
    print "|_D_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|_%s_|" %(comp_board[3][0], comp_board[3][1], comp_board[3][2], comp_board[3][3], comp_board[3][4], comp_board[3][5], comp_board[3][6], comp_board[3][7], comp_board[3][8], comp_board[3][9])
    print …
hondros 25 Junior Poster

um, here's what you do.
On your pc, make a file in your documents that is named something like:
runpython.pythonscript
It doesn't matter what it is, just so long as no one else will have it. Then, make a script that checks for that file in your documents, and if it's there, run the script on your flash drive
If not, then do nothing
Then, compile it using py2exe, and put it on your flash drive, along with the script, and the autorun.inf file.
That's how I'd do it

hondros 25 Junior Poster

Or, say a list of equipment, with each peice having it's own list of AC, slot to equip in, etc.
:D Just my $0.02 for games

hondros 25 Junior Poster

Here's what I think:
If it refrences outside objects at all, than it will be different if you have it on a different server. Check and make sure that all the folders and files are completely the same.

hondros 25 Junior Poster

:D I got it all figured out, and it's a lot more readable too:

import random

# Thanks to Vegaseat
user_board = []
comp_board = []
comp_boardu = []
for row in range(10):
    user_board.append(['O']*10)
    comp_board.append(['O']*10)
    comp_boardu.append(['O']*10)

def comp_placement2(ship):
    d = [random.randint(0, 9), random.randint(0, 9)]
    di = random.choice(["up", "down", "left", "right"])
    a = 0
    if comp_board[d[0]][d[1]] == "+":
        a = 0
    elif comp_board[d[0]][d[1]] == "O":
        if di == "up":
            if d[0] - ship[1] < 0:
                a = 0
            elif d[0] - ship[1] >= 0:
                a = 1
                for x in range(0, ship[1]):
                    if comp_board[d[0]-x][d[1]] == "+":
                        a = 0
                if a == 1:
                    for x in range(0, ship[1]):
                        comp_board[d[0]-x][d[1]] = "+"
                        a = 1
        elif di == "down":
            try:
                trying = comp_board[d[0]+ship[1]]
                a = 1
                for x in range(0, ship[1]):
                    if comp_board[d[0]-x][d[1]] == "+":
                        a = 0
                if a == 1:
                    for x in range(0, ship[1]):
                        comp_board[d[0]+x][d[1]] = "+"
                    a = 1
            except:
                a = 0
        elif di == "left":
            if d[1] - ship[1] < 0:
                a = 0
            elif d[1] - ship[1] >= 0:
                a = 1
                for x in range(0, ship[1]):
                    if comp_board[d[0]][d[1]-x] == "+":
                        a = 0
                if a == 1:
                    for x in range(0, ship[1]):
                        comp_board[d[0]][d[1]-x] = "+"
                        a = 1
        elif di == "right":
            try:
                trying = comp_board[d[1]+ship[1]]
                a = 1
                for x in range(0, ship[1]):
                    if comp_board[d[0]][d[1]+x] == "+":
                        a = 0
                if a == 1:
                    for x in range(0, ship[1]):
                        comp_board[d[0]][d[1]+x] = "+"
                    a = 1
            except:
                a = 0
    comp_placement2.a = a …
hondros 25 Junior Poster

All right, so I've been staring at the code, and I've been thinking, is there some way to have it select numbers that aren't already selected? And that won't go out of bounds?
! I got it!
I'll try soem while: loops, and check back with you

hondros 25 Junior Poster

Well, if you want it to be:
'(1.0+nfpermult+1.0)'
Then it appears that 'nf' will be at both the beginning and end, so I'll assume that the original is:
'nf+nfpermult+nf'
so, you do this:

a = 'nf+nfpermult+nf'
a = [2:-2]
b = '1.0'+a+'1.0'

Seems the easiest way to do it for me

hondros 25 Junior Poster

Okay, I'm creating a Battleship game. It's going to be using the console for now, still don't know GUI. Anyways, this is my issue. I have created two boards as lists, the first for the user, the second for the computer. I have the computer generate random numbers and a direction, and it places the ship there. I have put in several checkers, to ensure that they cannot be placed on top of each other, or go off the board. My issue, is that it seems to freeze, I would expect it to take a while, maybe no more than a minute, but it stays the same for 10 minutes, and then it crashes. Any help?

# import needed modules
import os
import random

# These are the boards
user_board = [['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O']]

comp_board = [['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],['O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'O'],['O', 'O', 'O', 'O', 'O', 'O', 'O', …
hondros 25 Junior Poster

:D I never knew about that module! I only knew about the math module... anyways, I like my method better, more work and thinking involved xD
Never mind the fact that I love math.

hondros 25 Junior Poster

Well... here's what I would do:
1) Ask the user how many rows and columns
ex: 2x2
2) Ask the user to input each number seperately
ex: 2, 3, -1, -2
3) Ask the user which letter to save the matrix to
ex: A
4) Save the matrix as:
A = ((2, 3), (-1, -2))
5) Loop that for needed matrices, then ask user which operation
ex: B = ((1, 2), (-1, -2))
6) for addition:

C_0_0 = A[0][0] + B[0][0]C_0_1 = A[0][1] + B[0][1]C_1_0 = A[1][0] + B[1][0]C_1_1 = A[1][1] + B[1][1]C_0 = C_0_0, C_0_1C_1 = C_1_0, C_1_1C = C_0, C_1C_0_0 = A[0][0] + B[0][0]
C_0_1 = A[0][1] + B[0][1]
C_1_0 = A[1][0] + B[1][0]
C_1_1 = A[1][1] + B[1][1]
C_0 = C_0_0, C_0_1
C_1 = C_1_0, C_1_1
C = C_0, C_1

Pretty much the same for subtracting. Multiplying two matrices together would be a bit tougher, but if you know how to do it by hand, you can figure it out in Python. Just find a way to loop the RxC when storing the matrix, or you can type it all out by hand
Say:

if R == 2 and C == 2:    A = ((0, 0), (0, 0))if R == 1 and C == 2:    A = ((0, 0))if R == 2 and C == 2:
    A = ((0, 0), (0, 0))
if R == 1 and C == 2:
    A = ((0, 0))

But I'm sure you can figure it out

hondros 25 Junior Poster

Yeah, I had just figured it out xD I was chatting with someone on Gmail, when I did a search, found eval(), then went back to my mail, and saw this xD Wierd, eh? But thanks, :D
Here's the data:

Hondros = ['Hondros', {'Equiped': [['Death Mask', [1, 0, 0, 0], 8, 6], ['Rags', [0, 1, 0, 0], 1, 1], ['Mocassins', [0, 0, 1, 0], 1, 1], ['Gauntlets', [0, 0, 0, 1], 6, 5]], 'Equipment': [1, 1, 1, 1], 'Stats': {'AC': 24, 'Strength': 15, 'Constitution': 14, 'Level': 1, 'HP': 12, 'Experience': 0, 'Dexterity': 12, 'Intelligence': 11, 'Base AC': 8, 'Wisdom': 12, 'HP max': 12}, 'Inventory': [['Death Mask', [1, 0, 0, 0], 8, 6], ['Rags', [0, 1, 0, 0], 1, 1], ['Mocassins', [0, 0, 1, 0], 1, 1], ['Gauntlets', [0, 0, 0, 1], 6, 5]], 'Gold': 0}]

Then, for saving, I do this: (I'm going to be adding a caesar shift later)

save = ""
for x in range(0, len(str(Hondros))):
		y = str(ord(str(Hondros)[x]))
		if len(y) < 3:
			y = "0"+y
		save = save + y
savefile = character[0] + ".sav"
f = open(savefile, "wb")
f.write(save)
f.close()

That gives a rather long list of numbers :D
And for loading the file's contents, I do this:

load = ""
for x in range(0, len(save), 3):
	load = load + chr(int(save[x:x+3]))
character = eval(load)

:D So yeah, if anyone wants to use my code as a template, go for it

hondros 25 Junior Poster

Okay, that's fine, for now I guess. But see, that'll allow for easy hacking of the character's when it is saved. What I am doing, is converting each of the ascii characters in the file to their corresponding number, and adding a shift, then saving it. Thus, I have to convert the list to an integer, but I can't convert it back... When I convert the numbers, I get a string, but I need a list. How do I convert the list?
But, I do thank you for showing me the pickle module, that works better than the standard open/write functions :D

hondros 25 Junior Poster

Okay, so I have a tuple for a game, and this is it: ['Hondros', {'Equiped': [['none', [], 0], ['Rags', [0, 1, 0, 0], 1, 1], ['Mocassins', [0, 0, 1, 0], 1, 1], ['Gauntlets', [0, 0, 0, 1], 6, 5]], 'Equipment': [0, 1, 1, 1], 'Stats': {'AC': 14, 'Strength': 15, 'Constitution': 14, 'Level': 1, 'HP': 12, 'Experience': 0, 'Dexterity': 12, 'Intelligence': 12, 'Base AC': 8, 'Wisdom': 11, 'HP max': 12}, 'Inventory': [], 'Gold': 0}] Anything inside it can change, including number of tuples inside the dictionaries. Anyways, this is how my program stores the character's information. There might be more added on. Now, this is what I want to do. I want to open a file, convert the tuple to a long integer, through use of the ord(). I've already done this, and saved it as character.sav, where character is the character's name. Now, when I open it, and convert it back, I now have a string of the above tuple. How do I go about reconverting it? Doing a tuple of it just makes it weird...

EDIT: Er... I seem to have my definitions of tuple and list confused... these are lists, not tuples. Oh well... same difference really

hondros 25 Junior Poster

Okay, I am in the middle of creating a rather large console RPG. It'll include ability to equip armor, weapons, interacting with NPC's, battles, saving/loading characters, etc. I don't want to save all of my classes and functions in the same file, for easier readability. I have a few questions:
1) Can I import .py files that are in the same folder to a separate .py file?
2) How does this change py2exe? Do I just setup the script for the main one, or all?

Thanks in advance!

hondros 25 Junior Poster

Sorry, I didn't see how old this was... my bad :D

hondros 25 Junior Poster

Hey, that'd work. But I just figured it out after I posted. Here's what I used:

for x in range(0, len(keycode)):
	y = ord(keycode[x])
	while x > 3:
		x = x -4
	matrix[x] = matrix[x] + y

Then again, yours is probably more efficient. But I tested a keycode of a length of 1,024 charecters, and it finished in about the same time. Thanks for the suggestion though :D

hondros 25 Junior Poster

Okay, so what I want to do, is to take the following code, and make it so that way it keeps continuning for all of the word.

keycode = raw_input()
matrix = [0, 0, 0, 0]
for x in range(0, len(keycode)):
    y = ord(keycode[x])
    if x > 3 and x <= 7:
        x = x -4
    if x > 7 and x <= 11:
        x = x -8
    if x > 11 and x <= 15:
        x = x -12
    if x > 15 and x <= 19:
        x = x -16
    matrix[x] = matrix[x] + y

The part I want to continue is the if statements... I'm thinking maybe using the len(keycode) somehow, but I'm a bit confused on where to go from here. Any help would be appreciated.

hondros 25 Junior Poster

Ah yes, I forgot to put that in there. Oh well. :D Thanks for pointing that out for him.

hondros 25 Junior Poster

http://www.python.org/doc/2.5.2/lib/module-random.html
That is the documentation for the random module. I suggest you take a look at it. Granted, it's not very discriptive of the function you're using, but I don't know what it does either. I think that it generates a float between the two numbers you put in or something. :/ Anyways, what are you using it for? I could give you a better solution using a different function

hondros 25 Junior Poster

Hey no problem. I've been coding for the past month, python is my first language. It took me a while to learn that. :D

hondros 25 Junior Poster

When you call it, are you just typing what it's called, or are you typing name(), and adding in any arguements? Note that even if your function or class does not require any arguements, when it's defined, you still need to add () after it, and when called, it should be as name(). Hope this helps :D

hondros 25 Junior Poster

This is what I would do. Create a loop for generating the numbers, and inside that loop, if the number is 1-10, then a = a + 1, 2-20, then b = b+ 1, etc., until you reach the end. Such as this [Note it's untested, this is just at template to get your brain working]:

import random
x = 0
while x <  (the number you want):
     rannum = random.randint(a, b) Where a and b are the numbers you define
     if rannum <= 10 and rannum >= 1:
          a = a + 1
     if rannum < 20 and rannum > 11:
          b = b + 1
print "The number of times a number was generated between 1 and 10 was: %d" %(a)
print "The number of times a number was generated between 11 and 20 was: %d" %(b)

Note that I'm not sure that %d is the one you use for integers. Hope this helps! :D

hondros 25 Junior Poster

This'll only work with the readable charecters, correct? I am planning on using this for an entire file, not only a .txt. Like, for example, a .exe, .jpg, .etc. Sorry for not making that clear in the first post. >> I feel a bit stupid now. Anyways, how would I get the hex values of the entire file? I understand that "fin = open(data_file, "rb")" is opening the file. What is the "rb", and is this possible with any file? I'm thinking it is, and the ord() gives the ascii code for the given string charecter. I don't think I need that, because I'm not dealing with the actual charecters.

hondros 25 Junior Poster

I am using python 2.6 for windows.

hondros 25 Junior Poster

Okay, this is what I am trying to do. I am attempting to create my own encrypter. I have the base encryption running, used just to encrypt a string you put in. I am going to add functionality to open a text file's contents and encrypt them, outputing them into another text file. I will be working on that later, so I might post up my questions if I can't figure it out. Anyways, this is what I need help with:
1) How do I open a file's binary code, and convert it to hex?
2) After opening it in hex, it shoud become manipulatable, such as, I can make it into a list, then change each odd charecter, correct?
3) After messing with the hex, how do I convert it back into binary, then save it?
Thank you very much in advance!
~ Hondros

hondros 25 Junior Poster

Hey, no problem. Glad I could help

hondros 25 Junior Poster

My opinion, if wanted, if I was in your situation, I would keep your laptop, not fix it, but I would buy a moniter for it. And also buy the new laptop. I'm sure you can find a cheap CRT moniter somewhere. Near where I live, there's a used computer store place, and I could get one for $50 at most. But yeah, buy the new laptop, than look around for a CRT moniter (the huge bulky ones, not LCD, in case you don't know)

hondros 25 Junior Poster

:D
I got it all finished, all working. Well, my Algebra 2 class just started Matrices, and for an extra credit project, we have to create an encoding matrix, 2x2, and code a message. So, I asked if I could make a program to code a message for me. She said as long as she showed me the program, and the code. :D So, this is all my functions to encode a message. It's very simple for now, but I'm going to make it more complex later, and have it include puntcuation, a caesar shift to begin with, reading files, etc. But anyways, here's my code:

################################
## Hondros' Encoder
## ~ Hondros
import string

a = 0

### Define the encoding matrix
def matrix_input(a):
    print 'First row, first column:'
    A_1_1 = int(raw_input(''))
    print 'First row, second column:'
    A_1_2 = int(raw_input(''))
    print 'Second row, second column:'
    A_2_1 = int(raw_input(""))
    print 'Second row, second column:'
    A_2_2 = int(raw_input(""))
    A_1 = (A_1_1, A_1_2)
    A_2 = (A_2_1, A_2_2)
    A = A_1, A_2
    matrix_input.A = A
    print 'Matrix A is:'
    print A_1
    print A_2


### Find determinant of the matrix
def determinant(encode_matrix):
    A = encode_matrix
    x = A[0][0]*A[1][1]
    y = A[1][0]*A[0][1]
    determinant.d = x - y


### Find the modified matrix
def modified(encode_matrix):
    B = encode_matrix
    d = determinant.d
    B_1_1 = B[1][1]
    B_1_2 = -B[0][1]
    B_2_1 = -B[1][0]
    B_2_2 = B[0][0]
    B_1 = (B_1_1, B_1_2)
    B_2 = (B_2_1, B_2_2)
    modified.m = (B_1, B_2)


### Find the inverse of the matrix
### This …
hondros 25 Junior Poster

Okay, here's something wierd. I'm using this from masterofpuppets:

letters = list( message )
alphabet = " abcdefghijklmnopqrstuvwxyz"
message_number = []

for letter in range( len( letters ) ):
    if letters[ letter ] in alphabet:
        for i in range( len( alphabet ) ):
            if letters[ letter ] == alphabet[ i ]:
                message_number.append( i )
                break

Okay, I get the numbers i need, but it excludes the first. Coding the phrase "Get help" returns: [5, 20, 0, 8, 5, 12, 16]. Oh. Wait... Entering "get help" returns: [7, 5, 20, 0, 8, 5, 12, 16]. Okay... so I guess now I need to learn how to make it all lowercase... That's using the string module... Shall do a search for that. Sorry I'm typing all this here xD It helps me think, and it'd be a good log for anyone doing what i'm doing. When I get this part working, I'll let you know what I'm actually doing

hondros 25 Junior Poster

@ masterofpuppets and Jilm:
Thank you for the shorter code :D That'll help when I create the second version of it. Since I am still learning Python, I want to try and do everything with what I know. And I was going to start using libraries, so that helps a great deal :D By the way, mop, love you name xD Master of Puppets is one of my favorite albums.

@ Murtan:
Thank you for pointing this out for me. :D

hondros 25 Junior Poster

Okay, here's my issue. I want to take a message a user enters, and then take it and convert it to a number, the standard a-z = 1-26, with space equaling 0. I haven't put in any punctuation yet. Anyways, I think I needed a loop, and I made this code to do it:

message = raw_input()

x = 0
y = 0
letters = list(message)
letters_len = len(letters)
message_number = []

while x < letters_len:
    if letters[x] == ' ':
        y = 0
        message_number.append(y)
        x = x+1
    if letters[x] == 'A' or 'a':
        y = 1
        message_number.append(y)
        x = x+1
    if letters[x] == 'B' or 'b':
        y = 2
        message_number.append(y)
        x = x+1
    if letters[x] == 'C' or 'c':
        y = 3
        message_number.append(y)
        x = x+1
    if letters[x] == 'D' or 'd':
        y = 4
        message_number.append(y)
        x = x+1
    if letters[x] == 'E' or 'e':
        y = 5
        message_number.append(y)
        x = x+1
    if letters[x] == 'F' or 'f':
        y = 6
        message_number.append(y)
        x = x+1
    if letters[x] == 'G' or 'g':
        y = 7
        message_number.append(y)
        x = x+1
    if letters[x] == 'H' or 'h':
        y = 8
        message_number.append(y)
        x = x+1
    if letters[x] == 'I' or 'i':
        y = 9
        message_number.append(y)
        x = x+1
    if letters[x] == 'J' or 'j':
        y = 10
        message_number.append(y)
        x = x+1
    if letters[x] == 'K' or 'k':
        y = 11
        message_number.append(y)
        x = x+1
    if letters[x] == 'L' or 'l':
        y = 12
        message_number.append(y)
        x = x+1
    if letters[x] == 'M' or …
hondros 25 Junior Poster

Thank you for the help. It works now

hondros 25 Junior Poster

Hi there
My Algebra 2 class just started matrices, and I don't want to go out and pay $100 for a graphing calculator, just for the matrices, when I can code one myself. So... this is my code, and I can do it without classes, but I decided to make things more tidy for myself. It's very basic for now, just defines two different 2x2 matrices, but I'm going slow so I don't screw up. The code works fine by itself, but if I put the functions in a class, I get an error. Here's the code:

#####################################
# I follow the matrices as such:
# matrix A =
# [ 1_1 1_2 1_3 ]
# [ 2_1 2_2 2_3 ]
# [ 3_1 3_2 3_3 ]
# [ 4_1 4_2 4_3 ]
# so on
print 'Simple Matrix Calculator'
print ''
print 'Enter the following:'
print '\'1 for Entering a matrix'
print '     \'1 for a 2x2 matrix'
print '          \'1\' for matrix A'
A = 0
B = 0


class matrix_2x2_define:
    def A(A):
        print 'First row, first column:'
        A_1_1 = int(raw_input())
        print 'First row, second column:'
        A_1_2 = int(raw_input())
        print 'Second row, second column:'
        A_2_1 = int(raw_input())
        print 'Second row, second column:'
        A_2_2 = int(raw_input())
        A_1 = (A_1_1, A_1_2)
        A_2 = (A_2_1, A_2_2)
        matrix_2x2_define.A.A = A_1, A_2
        print 'Matrix A is:'
        #print '[ '+A_1_1+' '+A_1_2+' ]'
        #print '[ '+A_2_1+' '+A_2_2+' ]'
        print A_1
        print A_2

    def B(B):
        print 'First row, first column:'
        B_1_1 = int(raw_input())
        print …
hondros 25 Junior Poster

Fixed it. Had to copy pywintypes.py, .pyc, and .pyo from:
C:\Python26\Lib\site-packages\win32\lib
to:
C:\Python26\Lib\site-packages
I then ran IDLE and typed:
import pythoncom
and it works fine :D

hondros 25 Junior Poster

Um, I'm not quite sure what you mean. I installed the package from Source Forge, and I have a whole bunch of new modules, so I guess so.

hondros 25 Junior Poster

Hey there. I've been programming in Python for about a month now. I've created simple programs for myself, such as games and e-mail applications. Still getting GUI down, I'll post if I need help there. Anyways, here's my problem:
Running: Windows XP
Python: Python 2.6

I installed the newest version of the Python for Windows Applications for v2.6 of Python. That went fine. It includes the module pythoncom, which I require. However, when I try to import pythoncom, I get the following:

Traceback (most recent call last):
  File "<pyshell#20>", line 1, in <module>
    import pythoncom
  File "C:\Python26\lib\site-packages\pythoncom.py", line 2, in <module>
    import pywintypes
ImportError: No module named pywintypes

How do I fix this problem? I already searched Google for an answer, and got pretty much nothing. It took me forever to even find pythoncom to download.
Thanks
~ Hondros