Post Reply 
Python comes to the Casio fx-CG 50
Yesterday, 02:25 AM (This post was last modified: Yesterday 02:44 AM by toml_12953.)
Post: #47
RE: Python comes to the Casio fx-CG 50
(Yesterday 12:24 AM)bxparks Wrote:  
(Yesterday 12:16 AM)toml_12953 Wrote:  How do you actually run a program? I have a program called Nqueens.py in the \PYTHON folder and I can't run it directly in shell mode, nor can I import it and run it.

- Upload the program to the CG50 using USB Mass Storage. I placed my files at the top level.
- Fire up PythonExtra.
- Press the FILES soft menu (F1) if not already there.
- You should see your file in a list.
- Scroll down to the file using the UP and DOWN arrow keys.
- Hit EXE to run.

My FILES screen looks like this:

That works if I don't have the program in a def block but if I do (see below) I get back to the >>> prompt and nothing I type seems to be able to run the program.

Code:
def nqueens():
  for i in range(100):
    a=[0] * 9
    r=8
    s=0
    x=0
    y=0
    t=0
    while True:
      x+=1
      a[x]=r
      while True:
        s+=1
        y=x
        while y>1:
          y-=1
          t=a[x]-a[y]
          if t==0 or x-y==abs(t):
            y=0
            a[x]-=1
            while a[x]==0:
              x-=1
              a[x]-=1
        if y==1:
          break
      if x==r:
        break
  print(s)

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Python comes to the Casio fx-CG 50 - toml_12953 - Yesterday 02:25 AM



User(s) browsing this thread: 5 Guest(s)