diff --git a/week-048.md b/week-048.md index 438ff7dc..6c95678e 100644 --- a/week-048.md +++ b/week-048.md @@ -87,3 +87,422 @@ fout.close() ``` then use `ls` and `cat` to see the files and to print the contents of the file. + + +## [DAY-362] files + +save and load the tictactoe state + +``` +symbol = 'X' +bord = ["-", "-", "-","-", "-", "-","-", "-", "-"] +ask = '' +while True: + print(bord[0], bord[1], bord[2]) + print(bord[3], bord[4], bord[5]) + print(bord[6], bord[7], bord[8]) + ask = input(f"{symbol} where do u want to play: ") + if ask == 'save': + f = open('board.txt',"w") + + for i in range(9): + f.write(bord[i]) + f.write(symbol) + f.close() + quit() + + elif ask== 'load': + f=open('board.txt','r') + data = f.read() + for i in range(9): + bord[i] = data[i] + symbol = data[9] + f.close() + continue + else: + if ask== 'a1': + bord[0] = symbol + if ask== 'a2': + bord[1] = symbol + if ask== 'a3': + bord[2] = symbol + if ask== 'b1': + bord[3] = symbol + if ask== 'b2': + bord[4] = symbol + if ask== 'b3': + bord[5] = symbol + if ask== 'c1': + bord[6] = symbol + if ask== 'c2': + bord[7] = symbol + if ask== 'c3': + bord[8] = symbol + win = False + if bord[0] != '-' and (bord[0]==bord[1] and bord[1] == bord[2]): + win = True + + if bord[3] != '-' and (bord[3]==bord[4] and bord[4] == bord[5]): + win = True + if bord[6] != '-' and (bord[6]==bord[7] and bord[7] == bord[8]): + win = True + if bord[0] != '-' and (bord[0]==bord[3] and bord[3] == bord[6]): + win = True + if bord[1] != '-' and (bord[1]==bord[4] and bord[4] == bord[7]): + win = True + if bord[2] != '-' and (bord[2]==bord[5] and bord[5] == bord[8]): + win = True + if bord[0] != '-' and (bord[0]==bord[4] and bord[4] == bord[8]): + win = True + if bord[2] != '-' and (bord[2]==bord[4] and bord[4] == bord[6]): + win = True + + if win == True: + print(symbol, "WINS") + quit() + + if symbol =='X': + symbol = '0' + else: + symbol = 'X' + + + +``` + + +## [DAY-363] files + +play with files + +``` +while True: + ask=input('What do u want to add on your duolingo file: ') + if ask == 'lessons': + f=open('duocount.txt','a') + f.write(ask) + f.write('\n') + ques=input('How many lesssons did you do: ') + f.write(ques) + if ask == 'placement': + t=open('duocout.txt','a') + t.write(ask) + t.write('\n') + question=input('which placement are your now: ') + t.write(question) + if ask == 'read': + d=open('duocount.txt','r') + d.seek(5) + print(d.read()) + if ask == 'quit': + break + +``` + + + +## [DAY-364] misc + +write few small programs, calculate area/circumference of a circle, volume and area of a rectangle, make a tiny chatgpt client, practice dictionary by making hiragana/eng and katakana/eng tabels + + +hiragana: + +``` +hiragana_dict = { + 'a': 'あ', + 'i': 'い', + 'u': 'う', + 'e': 'え', + 'o': 'お', + 'ka': 'か', + 'ki': 'き', + 'ku': 'く', + 'ke': 'け', + 'ko': 'こ', + 'sa': 'さ', + 'shi': 'し', + 'su': 'す', + 'se': 'せ', + 'so': 'そ', + 'ta': 'た', + 'chi': 'ち', + 'tsu': 'つ', + 'te': 'て', + 'to': 'と', + 'na': 'な', + 'ni': 'に', + 'nu': 'ぬ', + 'ne': 'ね', + 'no': 'の', + 'ha': 'は', + 'hi': 'ひ', + 'fu': 'ふ', + 'he': 'へ', + 'ho': 'ほ', + 'ma': 'ま', + 'mi': 'み', + 'mu': 'む', + 'me': 'め', + 'mo': 'も', + 'ya': 'や', + 'yu': 'ゆ', + 'yo': 'よ', + 'ra': 'ら', + 'ri': 'り', + 'ru': 'る', + 're': 'れ', + 'ro': 'ろ', + 'wa': 'わ', + 'wo': 'を', + 'n': 'ん', +} +while True: + eng = input("which letter do u want to translate: ") + actual = hiragana_dict[eng] + print(actual) +``` + +katakana: + +``` +japanese={ + "a": "ア", + "i": "イ", + "u": "ウ", + "e": "エ", + "o": "オ", + "ka": "カ", + "ki": "キ", + "ku": "ク", + "ke": "ケ", + "ko": "コ", + "sa": "サ", + "shi": "シ", + "su": "ス", + "se": "セ", + "so": "ソ", + "ta": "タ", + "chi": "チ", + "tsu": "ツ", + "te": "テ", + "to": "ト", + "na": "ナ", + "ni": "ニ", + "nu": "ヌ", + "ne": "ネ", + "no": "ノ", + "ha": "ハ", + "hi": "ヒ", + "fu": "フ", + "he": "ヘ", + "ho": "ホ", + "ma": "マ", + "mi": "ミ", + "mu": "ム", + "me": "メ", + "mo": "モ", + "ya": "ヤ", + "yu": "ユ", + "yo": "ヨ", + "ra": "ラ", + "ri": "リ", + "ru": "ル", + "re": "レ", + "ro": "ロ", + "wa": "ワ", + "wo": "ヲ", + "n": "ン", + "ga": "ガ", + "gi": "ギ", + "gu": "グ", + "ge": "ゲ", + "go": "ゴ", + "za": "ザ", + "ji": "ジ", + "zu": "ズ", + "ze": "ゼ", + "zo": "ゾ", + "da": "ダ", + "di": "ヂ", + "du": "ヅ", + "de": "デ", + "do": "ド", + "ba": "バ", + "bi": "ビ", + "bu": "ブ", + "be": "ベ", + "bo": "ボ", + "pa": "パ", + "pi": "ピ", + "pu": "プ", + "pe": "ペ", + "po": "ポ", + "ā": "ーア", + "ē": "ーエ", + "ō": "ーオ", + "kā": "ーカ", + "kī": "ーキ", + "kū": "ーク", + "kē": "ーケ", + "kō": "ーコ", + "sā": "ーサ", + "shī": "ーシ", + "sū": "ース", + "sē": "ーセ", + "sō": "ーソ", + "tā": "ータ", + "chī": "ーチ", + "tsū": "ーツ", + "tē": "ーテ", + "tō": "ート", + "nā": "ーナ", + "nī": "ーニ", + "nū": "ーヌ", + "nē": "ーネ", + "nō": "ーノ", + "hā": "ーハ", + "hī": "ーヒ", + "fū": "ーフ", + "hē": "ーヘ", + "hō": "ーホ", + "mā": "ーマ", + "mī": "ーミ", + "mū": "ーム", + "mē": "ーメ", + "mō": "ーモ", + "yā": "ーヤ", + "yū": "ーユ", + "yō": "ーヨ", + "rā": "ーラ", + "rī": "ーリ", + "rū": "ール", + "rē": "ーレ", + "rō": "ーロ", + "wā": "ーワ", + "wō": "ーヲ", + "vū": "ーヴ", + "n": "ーン", + "ga": "ガ", + "gi": "ギ", + "gu": "グ", + "ge": "ゲ", + "go": "ゴ", + "za": "ザ", + "ji": "ジ", + "zu": "ズ", + "ze": "ゼ", + "zo": "ゾ", + "da": "ダ", + "ji": "ヂ", + "zu": "ヅ", + "de": "デ", + "do": "ド", + "ba": "バ", + "bi": "ビ", + "bu": "ブ", + "be": "ベ", + "bo": "ボ", + "pa": "パ", + "pi": "ピ", + "pu": "プ", + "pe": "ペ", + "po": "ポ", + "ya": "ャ", + "yu": "ュ", + "yo": "ョ", + "tsu": "ッ", + "a": "ァ", + "i": "ィ", + "u": "ゥ", + "e": "ェ", + "o": "ォ", + "wa": "ヮ", + "wi": "ヰ", + "we": "ヱ", + "vu": "ヴ", +} +while True: + eng = input("which letter do u want to translate: ") + actual = japanese[eng] + print(actual) + +``` + +french counting: + +``` +FrenchCounting={ + "one":"un", + "two":"deux", + "three":"trois", + "four":"quatre", + "five":"cinq", + "six":"six", +} +score = 0 +while True: + eng = input("which number: ") + fre = input("what is the french version: ") + + actual = FrenchCounting[eng] + if actual == fre: + print("success") + score +=1 + print(score) + else: + print("wrong") +``` + + +openai client: + +``` +import openai +openai.api_key = 'sk-..' +messages = [{"role": "system", "content": "You are a japanesec techer, and your student is asking you the following quesiton, answer with the right response."}] +while True: + question = input("what is your question: ") + messages.append({"role": "user", "content": question}) + + response = openai.ChatCompletion.create( + model="gpt-3.5-turbo", + messages=messages + ) + content = response["choices"][0]["message"]["content"] + + print('-' * 20) + print(content) + + messages.append({"role":"assistant", "content": content}) + print('-' * 20) + #print(messages) +``` + + +area and volume of an parallelepiped: + +``` +H = float(input("what is the height: ")) +W = float(input("what is the width: ")) +D = float(input("what is the depth: ")) + +V = H*W*D +A = H*W*2 + H*D*2 + W*D*2 +print("The Volume is: "+str(V)) +print("The Area is: "+str(A)) +``` + +area and circumference of a circle: + +``` +ask = input("How big is the radius: ") +r=float(ask) +pi = 3.1415926 +C =2*pi*r +A =pi*r*r +print("the Area of your circle is: "+str(A)) +print("the Circumference is: "+str(C)) +``` + +