Freaky_Chris 299 Master Poster

Well it would be

(546 % 10^x)/10^(x-1)

where x = number of digits in number

Freaky_Chris 299 Master Poster

You could store all the numbers in an array as suggested and then print them out, or you can do something like this...

num = 546

mostsigdigit = (546 % 10^3)/10^2


probably gave too much away there but oh well

Freaky_Chris 299 Master Poster

The fun part is getting the digits to print out from most significant to least significant, as per your example using 3456. If you just print num % 10 in the while loop, you can get the digits in reverse. To print in the right order, you need to store the digits somewhere (the simpler solution, IMO), or extract the digits from most significant to least significant.

This is what i was thinking about from the go was to get them in the correct order, so maybe my post may give you a small clue

Freaky_Chris 299 Master Poster

A combination of modulus division and normal division will do this nicely for you.

You have way to many steps, you can retreive each number in 1 line of code using both normal and modulus division.

its all to do with 10^x in a way xD

Chris

Freaky_Chris 299 Master Poster
# adding to christ o'leary's fight function
# to have integer returned use
# x = random.choice([0, 1])
# print x, type(x) # testing

# or x = random.randrange(0, 2)
# print x, type(x)
import random

def main():
    global monster_HP1
    monster_HP1 = 5
    global hp
    hp = 10
    print """you are in a fight!
    Type 'h' to fight"""
    x = raw_input(': ')
    if x == 'h':
        fight_unicorn()
    else:
        print "Error"
        main()
        
def fight_unicorn():
    global monster_HP1
    global hp
    hit_miss = random.randrange(0, 2)
    #print x, type(x)
    if hit_miss == 1:
        print "You hit the monster!"
        monster_HP1 = monster_HP1 - 1
        if monster_HP1 == 0:
            print "You win!"
            master_bedroom()
        else:
            monster_turn1()
    else:
        print "You Missed"
        monster_turn1()
def monster_turn1():
    monster_hit = random.randrange(0, 2)
    #print x, type(x)
    global hp
    if monster_hit == 1:
        print "You are hit!"
        hp = hp-1
        if hp == 0:
            print "Game Over"
        else:
            fight_unicorn()
    else:
        print "The monster missed"
        fight_unicorn() # ADD IN
main()

i simply took out the print x, type(x) and added in a call back to fight unicorn

Chris

Freaky_Chris 299 Master Poster

Is that all your compiler tells you about the error? That is not the reason since it is the LINKER that has thrown the error up which means it has compileid fine just the linker.

Chris

Freaky_Chris 299 Master Poster

I'm wondering if you paid attention to arkM now since the very first sentence that he said solves your problem and it compilies, although not the best code every as pointed out.

Chris

Freaky_Chris 299 Master Poster

Well my only suggestion is that it is in character.h, since that is where it appears those classes and functions are defined

Freaky_Chris 299 Master Poster

nvm shush i should think

perhaps its in your other file

Freaky_Chris 299 Master Poster

Their big goal is to dethrone C/C++ from kingship of gaming programming!

Good luck to them on that one, as an interpreted language its not exactly the fasted language out there. Although i must say Oblivion use Python very well, but that isn't so much Pygame as far as im aware.

Chris

Freaky_Chris 299 Master Poster

Perhaps this will help

Freaky_Chris 299 Master Poster

Hmm lets try adding code tags, so it becomes a bit more readable. Also couldyou give us a little clue as to what problems you are actually having cause thats alot to look over when we don't know what were looking for

Chris

Freaky_Chris 299 Master Poster

Hey, does anybody know any good tutorials for MPASM for the 16F PIC micro controllers?

Thanks for any help.

Chris

Freaky_Chris 299 Master Poster

I'm not sure if I fully understand what your problem is. However you may wish to look into

os.walk()
os.path

You may find these helpful in locating and accessing files on a system.

Chris

Freaky_Chris 299 Master Poster

Tkinter is the easier, and has one big advantage; its standard.

However i personally find hat wxPython is better although slightly harder to learn.

Chris

Freaky_Chris 299 Master Poster
m= start[0]*60+start[1]
n= finish[0]*60+finish[1]

here there is a problem, start[0] refers to the first character in the string start. so from your exmaple of 14, 12 start[0] would be 1. and start[1] would be 4. Also you would need to convert those to intergers before multiplying by 60 otherwise you will end up with

111111111111....60 of them.

Hope you can see where you are going wrong.

Chris

Freaky_Chris 299 Master Poster

Sorry for double post.

One thing to notice is that you can probably save yourself space here. Forexampe you have the following script

import time
def myScriptsContents():
   #some code
   #some more code

while True:  #begin your infinite loop
   myScriptsContents()
   time.sleep(30)

Notice how much simple this is but should still have the same effect.

Chris

Freaky_Chris 299 Master Poster

not a problem, glad i could help

Chris

Freaky_Chris 299 Master Poster

Your more than welcome

Chris

Freaky_Chris 299 Master Poster

does ctrl + c not work? this is a basic interupt command.

Chris

Freaky_Chris 299 Master Poster

This section is to do with importing, when a file is run on its own as an indervidual script the contents of this section is run. When the file is imported this section of code isn't run, here a short example to demonstrate this.

if __name__ == '__main__':
   print "I was not imported!"
else:
   print "I was imported!"

run this code straight and run it by importing it you will see the effects.

The reason behind this is so a standalone script can have its functions imported into other scripts without the body of the code being run.

Chris

Freaky_Chris 299 Master Poster

do something like this

import time, MyScript
while True:
   MyScript.main()
   time.sleep(30)

and for MyScript.py

def main():
   #your stuff here

if __name__ == '__main__':
   main()

hope this helps

Chris

Freaky_Chris 299 Master Poster

perhaps you could run a different script that calls the scripts you want to run every 30 seconds, also if your on windows you could call os.system("cls") from within your script assuming you have imported the os module 'import os' this will clear the console for you. Im sure there is something similar under linux.

Hope this helps,

Chris

Freaky_Chris 299 Master Poster

This is trusting you have python install on your pc. Im guessing you don't since if you did then you could simply double click the file and it would run, if your on windows.

If your on linux you need to change the access rights via chmod to 755 to be able to run it, then just double click and click run in terminal.

Chris

Freaky_Chris 299 Master Poster

wxPython, will aid you with GUI so will Tkinter (whic is built it). They will also allow basic graphics. For more detials graphics have a look at PyGame.

Chris

Freaky_Chris 299 Master Poster

You should look into the os module as i suggested as this allows you to do alot of things. here is an example

import os
for path, dirs, files in os.walk("C:"):
   print path, dir, files

ofcourse this is a very basic example and can be expanded greatly. You can loop through files

for path, dirs, files in os.walk("C:"):
   for f in files:
      print f

so as you can see this way you can do alot of things this way. You can store the files use them to do other things with whatever.

Chris

Freaky_Chris 299 Master Poster

this is just the way python does it, this doesn't affect you in anyway does it?

Chris

Freaky_Chris 299 Master Poster

indeed it is possible, very easy actually

import os
os.system("cd [directory]")

and if you want to make it so that you can type commands into your python commandline

import os
while True:
   command = raw_input("Enter Command->")
   if command.upper() == "Q":
      break
   try:
      os.system(command)
   except:
      print "invalid command\n"

One thing to note is that if you are just going to make specific calls to the command line to do one thing such as cd directory, you should use the python os module rather than just calling the comman shell.

To perform a cd command from python you ould use the following

import os
os.chdir("C:\\A folder")

This changes the current working directory to C:\Folder. From there you cann call other functions to make directories etc.

Python: os module or type help("os") in the Python command line

you should also look at os.name and os.path especially, help("os.name") etc for information on these.

Hope this helps, just be careful if you do allow user input to access the command prompt.

Chris

Freaky_Chris 299 Master Poster

Yes indeed that is a good way to solve it. Now i have looked at the pictures i can see what your problem really was. And yes how you have done it is correct

Freaky_Chris 299 Master Poster

put all of your code here in [ /code] tags so we can have a proper look

Chris[code=python][ /code] tags so we can have a proper look

Chris

Freaky_Chris 299 Master Poster

again that is just a case of doing a simple check,

if x+z > 10:
   x += z
   x -= 10
   x = 10 - x
   set_xpos(x)

im sure there is a cleaner way but i can't see it right now.

Chris

Freaky_Chris 299 Master Poster
for word in list:
            print word+",",

or did i just miss what you asked?

Freaky_Chris 299 Master Poster
def dela(c):
     sum=0
     pile = []
     while sum < c:
         b = random.randrange (1, 10 - sum + 1)
         pile.append(b)
         sum += 1
     print pile,sum
     return sum, pile
def ordna(x):
    b = 0
    y = []
    for num in x:
        new_num = num-1
        if new_num<0:
            del new_num
        else:
            y.append(new_num)
            b+=1
    y.append (b)
    y.sort()
    y.reverse ()
    print " ".join(map(str,y))
    return y
c=lasin ()
pile=dela(c)
ordna(pile)

This is fine you can use both a and b that are returned, when you return them in the way you have the result is a tuple.

just means that you have to access each bit indervidual.

so to use the list of numbers that is returned in this case you would have to put

ordna(pile[1])

If you print them you will see that you can access both

print pile[0]
print pile[1]

Notice that the first line will print the interger that you returned and the second line will print the list of numbers you returned.

Chris

Freaky_Chris 299 Master Poster

ok ignore me ranting on about geometric series, the fact you are withdrawing x throws it out.

Chris

Freaky_Chris 299 Master Poster

when you set your x and y positions you need to check to if the new postion will be >10 or <1 if so it is an invalid move.

Please use [code] tags this will keep indenting and make it possible to actually read our code.

You need to then report this and take actions based around this.

Chris

Freaky_Chris 299 Master Poster

One thing to note is that you have to do the calculations over and over until the money is depleted.

One thing i would do is consider how i would ad interest. id they enter 6% that is the same as balance*0.06. That is how much interest is added to be added on.

So balance*1.06 = new balance after interest added on. This is a geometric series with the common ration r=1.06 (in this case) and n is unknown.

geometric series use the following formula

Un = ar**(n-1)

where r is the common ration, and a is the first term.
note you will also have to include the fact that x is taken of at the start of each month, which could be something like this not entrily sure don't have the time to sit and work it out right now but

Un = ar**(n-1) - x*(n-1)


This gives us to methods of solving this problem, one is to loop through and do each step and count how many months it takes. The second option is to use maths and logarithms to calculate the vale of n based of a geometric series. It is upto you how you wish to go about solving this problem.

hope this proves helpful
Chris

Freaky_Chris 299 Master Poster

First print --> [2, 5, 7, 7] 4
Second print --> (4, [2, 5, 7, 7])

the first print is showing 2 different objects.
The second print is showing 1 object.

Read about lists & tuples, embedding in particular, this may help you understand

Chris

Freaky_Chris 299 Master Poster

It works perfectly, you just need to read about unicode(UTF-8) encoding and other data encoding. By default you are using ascii....which arabic characters do not fall under.

Chris

Freaky_Chris 299 Master Poster

Indeed, after the def statement everything indented is included in the function for example.

def myfunc():
   #in function
   #still in function
   #when in a function you can use normal indenting
   #as long as you have the first indent as well
#this has ended the function definition since it is not indented.

Hope that helps

Chris

Freaky_Chris 299 Master Poster
fsz += os.path.getsize( os.path.join(path, f) )

Above is what i normally call providing there is no error thrown due to the file naming etc being too long.

Below is what i call if the file name / dir is too long.

os.chdir( path )
fsz += os.path.getsize( f )

to me this is fine. If you can see something wrong with this then please tell me.

chris

Freaky_Chris 299 Master Poster

what you saying is you want to use the same bit of code over and over?
sorry if this is not what you are asking
if so then you use a function

def myFunction(param1, param2):
   print param1
   print int(param2)**3

myFunction("Hello", 2)
myFunction("Joe", 3)

Hope this helps


Chris

Freaky_Chris 299 Master Poster

that is what i was thinking, but i was also thinking that it works fine for shorter lists, so i was guessing he wouldn't actual do that

Chris

Freaky_Chris 299 Master Poster

Indeed there is

while True:
  overWrite = raw_input("Would you like to overwrite log file? (y/n)->")
  if overWrite.upper() == "Y":
     break
  elif overWrite.upper() == "N":   
     break
  else:
     print "Invalid Option\n"

ignore naming of variables etc, thats just taken from something im working on myself right now.

Chris

Freaky_Chris 299 Master Poster

you could split your list in to 2 smaller lists and process them indervidualy.

Also you may wish to look into vectors

Chris

Freaky_Chris 299 Master Poster

mywxpythonscript.pyw

this will then run with pythonw.exe which doesn't run the commandline window

Chris

Freaky_Chris 299 Master Poster

Simple read the use file.readlines() on both files to give you 2 arrays

so something like this

f1 = open("file1.txt", "r")
f2 = open("file2.txt", "r")

fileOne = f1.readlines()
fileTwo = f2.readlines()
f1.close()
f2.close()
outFile = open("results.txt", "w")
x = 0
for i in fileOne:
   if i != fileTwo[x]:
      outFile.write(i+" <> "+fileTwo[x])
   x += 1

outFile.close()

something along those lines

Chris

Freaky_Chris 299 Master Poster

I have just tested this to see if it works, and unfortuantly not, it is now throwing an error saying cannot find the file, im guessing this is because the name is too long.

is there a version of getsize that allows for bigger file names?

WindowsError: [Error 3] The system cannot find the path specified:

note this file does exist and is not inuse by another application

Chris

Freaky_Chris 299 Master Poster

Thanks vega i had a feeling it would come down to that, i will test it when i get home as im currently in college. But i am testing is on a memory stick and i have set up my script so that as it iterates through the files it changes the current working dir to that of the file im retrieving the size of, then i retrieve the size and finally return to the original dir of the python script ready to output results to the text file.
This is done if an exception is thrown, other wise i just call os.path.getsize() on the whole file location.

It seems to work fine i just need a long file to test it on.

Chris

Mark Carlson commented: Hi Chris, Found LongPathTool program useful +0
Freaky_Chris 299 Master Poster

One way is to raise you own exception and then catch it with a break.

class myException(Exception): pass
w = input("Enter width")
h = input("Enter height")

for x in range(0,w):
    for y in range(0,h):
        print x,y
        if (raw_input("Stop? y/n") == "y"):
            raise myException
    except myException:
       break

any help?

Chris

Freaky_Chris 299 Master Poster

Its probably including the path in that case then, since the whole path C:\\..............\\whatever including the file is 305 characters long.

Chris