Related to: Python
anonymous GuessingGame.py
Python
#GuessingGame.py
import random

Guess_num=random.randint(1,10)
i = r = 3
while i > 0:
    my_num=int(input("What's number? : "))
    if my_num > Guess_num:
        print('too big!')
        i -= 1
    elif my_num < Guess_num:
        print('too small!')
        i -= 1
    else:
        print('Congratuation!')
        r = i =0

if not r :
    print(f'You Win. The number is {Guess_num}')
else:
    print(f'You Loose. The number is {Guess_num}')
anonymous Pythonで転置式暗号
Public Domain Python
#ENCRYPTING WITH THE TRANSPOSITION CIPHER

def main():
  myMessage = 'Common sense is not so common.'
  myKey = 8

  print(f'Key : {myKey}\nPlaneText : {myMessage}\nCipherText :{enc_box}')   

def encryptMessage(key, message):

  box=['']
  counter=0
  for i in message:
    box[counter] += i
    if len(box[counter]) == key:
      counter += 1
      box.append('')

  enc_box=''
  for i in range(myKey):
    for k in box:
      if i < len(k):
        enc_box += k[i]

    return enc_box

if __name__ == '__main__':
  main()
anonymous PythonでCaesar Cipher をbrute force
Public Domain Python
#HACKING THE CAESAR CIPHER WITH THE BRUTE-FORCE TECHNIQUE

alpha='abcdefghijklmnopqrstuvwxyz'.upper()
LETTER=''

Text='GUVF VF ZL FRPERG ZRFFNTR.'

for i, k in enumerate(alpha):
  shift=alpha.find(k)
  for j in Text:
    pos=alpha.find(j)
    if pos < 0:
      LETTER += j
    else:
      LETTER += (alpha*2)[pos+shift]
  print(f'Key#{str(i).zfill(2)} : {LETTER}')
  LETTER = ''
anonymous PythonでCaesar Cipher in Cryptography
Public Domain Python
#Caesar Cipher in Cryptography

def encrypt(text,s):
  alpha='abcdefghijklmnopqrstuvwxyz'
  cipher=(alpha*2)[s:s+26]
  output=''
  for i in text.lower():
    output +=cipher[alpha.find(i)] if i in alpha else i
  return output.upper()

def main():
  Text=input('Text :')
  Shift=int(input('Shift :'))
  
  print(f'Output : {encrypt(Text,Shift)}')

if __name__ == "__main__":
  main()
𝗜𝗭 Markdownのカレンダーテーブルを出力する
MIT Python
import datetime, locale

locale.setlocale(locale.LC_TIME, 'ja_JP.UTF-8')
row_date = datetime.date.today()

print("|日付|予定|メモ|")
print("|:---:|:---|:---|")

for i in range(15):
  row = "| "
  row += str(row_date.strftime("%m/%d %a "))
  row += "| "
  if row_date.weekday() == 0: #月曜
    row += ""
  elif row_date.weekday() == 1: #火曜
    row += ""
  elif row_date.weekday() == 2: #水曜
    row += ""
  elif row_date.weekday() == 3: #木曜
    row += ""
  elif row_date.weekday() == 4: #金曜
    row += ""
  elif row_date.weekday() == 5: #土曜
    row += ""
  elif row_date.weekday() == 6: #日曜
    row += ""
  row += " |  |"
  print(row)
  row_date += datetime.timedelta(days=1)
anonymous PythonでTurtleで五輪
Python
import turtle as t

kame = t.Turtle()
kame.hideturtle()


def draw_circle(line_color):
    kame.color(line_color)
    kame.pensize(7)
    kame.circle(100)


def kame_move(x, y):
    kame.penup()
    kame.goto(x, y)
    kame.pendown()


kame_move(-220, 55)
draw_circle('#0081c8')

kame_move(-110, -55)
draw_circle('#fcb131')

kame_move(0, 55)
draw_circle('#000000')

kame_move(110, -55)
draw_circle('#00a651')

kame_move(220, 55)
draw_circle('#ee334e')
Programmerryoki 1292. Maximum Side Length of a Square with Sum Less than or Equal to Threshold In Python Brute Force
Python
class Solution:
    def maxSideLength(self, mat: List[List[int]], threshold: int) -> int:
        for n in range(1, min(len(mat), len(mat[0]))+1):
            done = False
            for b in range(len(mat)-n+1):
                for a in range(len(mat[0])-n+1):
                    s = sum([sum(mat[i][a:a+n]) for i in range(b,b+n)])
                    if s <= threshold:
                        done = True
                        break
                if done:
                    break
            else:
                return n-1
        return min(len(mat),len(mat[0]))
12