pi.py

Created by stimorol

Created on March 23, 2023

2.69 KB


from math import *
from random import *
from ion import *
from kandinsky import *
from time import *

pi=[1,4,1,5,9,2,6,5,3,5,8,9,7,9,3,2,3,8,4,6,2,6,4,3,3,8,3,2,7,9,5,0,2,8,8,4,1,9,7,1,6,9,3,9,3,7,5,1,0,5,8,2,0,9,7,4,9,4,4,5,9,2,3,0,7,8,1,6,4,0,6,2,8,6,2,0,8,9,9,8,6,2,8,0,3,4,8,2,5,3,4,2,1,1,7,0,6,7,9,8,2,1,4,8,0,8,6,5,1,3,2,8,2,3,0,6,6,4,7,0,9,3,8,4,4,6,0,9,5,5,0,5,8,2,2,3,1,7,2,5,3,5,9,4,0,8,1,2,8,4,8,1,1,1,7,4,5,0,2,8,4,1,0,2,7,0,1,9,3,8,5,2,1,1,0,5,5,5,9,6,4,4,6,2,2,9,4,8,9,5,4,9,3,0,3,8,1,9,6,4,4]
keyNumbers=[KEY_ZERO, KEY_ONE, KEY_TWO, KEY_THREE, KEY_FOUR, KEY_FIVE, KEY_SIX, KEY_SEVEN, KEY_EIGHT, KEY_NINE] 
keySelection=[KEY_ONE, KEY_TWO, KEY_THREE]

def erase():
  draw_string("                               \n                                   \n                                                  \n                             \n                                  \n                                   \n                                   \n                                   \n                                   ",25,25)
  

def learn():
  erase()
  decimalNumber=(-1)
  output="3."
  draw_string(output,25,25)
  stop=False
  while not stop:
    if keydown(KEY_RIGHT):
      while keydown(KEY_RIGHT):
        pass
      decimalNumber+=1
      output+=str(pi[decimalNumber])
      if len(output)%26 == 0:
        output+="\n     "
      draw_string(output,25,25)
    if keydown(KEY_EXE) or keydown(KEY_OK):
      while keydown(KEY_EXE) or keydown(KEY_OK):
        pass
      stop=True
      selection=0
    
def test():
  erase()
  output="3."
  stop=False
  score=0
  draw_string(output,25,25)
  while True:
    for i in keyNumbers:
      if keydown(i):
        while keydown(i):
          pass
        output+=str(keyNumbers.index(i))
        if int(keyNumbers.index(i)) == pi[score]:
          draw_string(output,25,25)
          score+=1
        else:
          sleep(0.1)
          draw_string("GAME OVER\n\n            SCORE="+str(score)+"\n\n            RETRY ?",113,45)

def showPi():
  output="3."
  erase()
  for i in range(1,len(pi)):
    output+=str(pi[i])
    draw_string(output,25,25)
    sleep(0.065)
    if len(output) == 26 or len(output) == 55 or len(output) == 84 or len(output) == 113 or len(output) == 132 or len(output) == 151 or len(output) == 180:
      output+="\n     "
    

def mainMenu():
  selection=None
  stop=False
  draw_string("PI\n\n           1: LEARN\n           2: TEST\n           3: SHOW PI",145,50)
  while not stop:
    for i in keySelection:
      if keydown(i):
        while keydown(i):
          pass
        selection=int(keySelection.index(i)+1)
        stop=True
  if selection == 1:
    learn()
  elif selection == 2:
    test()
  elif selection == 3:
    showPi()
mainMenu()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.