Friday, February 28, 2020

Starting Tic Tac Toe in Python

L = ["X", " ", " ", " ", "O", " ", " ", " ", " "]

while True:
  V0 = "     |     |      "
  V1 = "  " + L[0] + "  | " + L[1] + "   |  " +  L[2]
  V2 = "_____|_____|______"
  V3 = V0
  V4 = "  " + L[3] + "  |  " + L[4] + "  |  " +  L[5]
  V5 = V2
  V6 = V0
  V7 = "  " + L[6] + "  |  " + L[7] + "  |  " +  L[8]
  V8 = V0
  
  print(V0)
  print(V1)
  print(V2)
  print(V3)
  print(V4)
  print(V5)
  print(V6)
  print(V7)
  print(V8)
  input()

Police mug shot sketch in Python

def hat():
  print("  -------")
  print("  |     |")
  print(" ---------");

def bald():
  print("")
  print("  .......")
  print("  .     .")

def spiky():
  print("")
  print(" \\|||||||/")
  print("  |     |")

def wideEyed():
  print(" (| O O |)")

def spectacled():
  print(" (|-0-0-|)")

def smallEyed():
  print(" (| . . |)")

def largeNose():
  print("  | /_\\ |")

def pugNose():
  print("  |  ^  |")

def mediumNose():
  print("  |  >  |")

def smiling():
  print("  |\\___/|")
  print("   -----")

def frowning():
  print("  |/---\\|")
  print("   -----")

def bearded():
  print("  |||-|||")
  print("   |||||")
  print("    |||")

while True:
  print("Choices for HAIR  type: 1. Hat     2. Bald       3. Spiky")
  print("Choices for EYE   type: 1. Wide    2. Spectacled 3. Small")
  print("Choices for NOSE  type: 1. Large   2. Pug        3. Medium")
  print("Choices for MOUTH type: 1. Smiling 2. Frowning   3. Bearded")
  features = int(input("Enter your choices: "))
  print()

  mouth = features % 10;
  nose = (features // 10) % 10;
  eye = (features // 100) % 10;
  hair = (features // 1000) % 10;
  
  if hair == 1:
    hat()
  elif hair == 2:
    bald()
  elif hair == 3:
    spiky()

  if eye == 1:
    wideEyed();
  elif eye == 2:
    spectacled()
  elif eye == 3:
    smallEyed()

  if nose == 1:
    largeNose()
  elif nose == 2:
    pugNose()
  elif nose == 3:
    mediumNose()

  if mouth == 1:
    smiling()
  elif mouth == 2:
    frowning()
  elif mouth == 3:
    bearded()

Saturday, February 15, 2020

Playing sound in Python

# Playing .mp3

from playsound import playsound      # Must be installed

s = "Believers Church Residential School"

for i in s:
  print(i, end='')
  if i == ' ':
    playsound("Silence.mp3")     # Uploaded to My Drive\Python
  else:
    playsound("Typewriter1.mp3") # Uploaded to My Drive\Python


# Playing .wav

import winsound

filename = 'LionRoar.wav'
winsound.PlaySound(filename, winsound.SND_FILENAME)