2023年12月4日 星期一

Green Judge Ref

 # name = 'Tom'

# age = 36

# print('My name is' ,name + '.','I am',age, 'years old.' )

# print('My name is ' + name + '. ' + 'I am '+ str(age) + ' years old.' )

# print('My name is' ,name + '.','I am',age, 'years old.' ,sep='**')


# print(f'My name is {name} I\'m {age:<6} years old.')

# print(f'My name is {name} I\'m {age:>6} years old.')


# s = 10.14159

# print(f'我的月薪${s:.2f}萬')


# for i in range(2,10):

#     for j in range(2,10):

#         # print(i,'*',j,'=',i*j)

#         print(f'{j}*{i}={i*j:>2}',end='   ')

#     print()


# q29

# a,b = map(int,input().split())

# s = 0

# for i in range(a,b+1):

#     if i == b:

#         print(i,end='=') 

#     else:

#         print(i,end='+') 

#     s = s + i

# print(s)



# q30

# a,b = map(int,input().split())

# s = 0

# if b>=a:

#     for i in range(a,b+1):

#         if i == b:

#             print(i,end='=') 

#         else:

#             print(i,end='+') 

#         s = s + i

# else:

#     for i in range(a,b-1,-1):

#         if i == b:

#             print(i,end='=') 

#         else:

#             print(i,end='+') 

#         s = s + i

# print(s)



#Q27

# n = 5

# for i in range(n,-1,-1):

#     print(i,end=' ') 


#Q26

# n = 3

# for i in range(n):

#     print('I love you.')


#q25

# d = input()

# print(d[::-1])


# Q24

d = '12345'

s = 0

for i in d:

    s = s + int(i)

print(s)

2023年11月23日 星期四

有道理, 但AI改變了什麼?

 

資料來源:李海碩台大語言中心演講

2023年11月20日 星期一

查表

 # a = ['apple','orange']

# b = ['蘋果','柳橙']

# indata = input('請輸入英文水果名:')


# if indata == 'apple':

#     print('蘋果')

# if indata == 'orange':

#     print('柳橙')


# a = '0123456789ABCDEF'

# b = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]


# indata = input('請輸入16進位數字:')

# i = 0

# while a[i] != indata:

#     i+=1

# print(b[i])


# a = '0123456789ABCDEF'

# b = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]

# indata = 'E'

# f =  a.find(indata)

# print(b[f])


# f1 = a.find('F')

# print(b[f1])


# a = ['I','IV','V','IX','X']

# b = [1,4,5,9,10]


# indata = 'VII'


# n = 0

# for i in indata:

#     f = a.index(i)

#     n=n + b[f]

# print(n)


# a = ['I','IV','V','IX','X','XL','L']

# b = [1,4,5,9,10,40,50]


# indata = 'IXVIIIXXL'


# n = 0

# i = 0

# while  i <len(indata):

#     if indata[i:i+2] in a:

#         f2 = a.index(indata[i:i+2])

#         n = n +b[f2]

#         i = i +2

#     else:

#         f = a.index(indata[i])

#         n=n + b[f]

#         i = i +1

# print(n)


# a = ['I','IV','V','IX','X','XL','L']

# b = [1,4,5,9,10,40,50]


d = {'I':1,'IV':4,'V':5,'IX':9,'X':10,'XL':40,'l':50}

indata = 'IXVIIIXXL'


n = 0

i = 0

while  i <len(indata):

    if indata[i:i+2] in d:

        n = n +d[indata[i:i+2]]

        i = i +2

    else:

        n = n +d[indata[i]]

        i = i +1

print(n)

2023年11月6日 星期一

text to Speech Sample

# 先在console 視窗下  pip install gTTs

 from gtts import gTTS

import os

import subprocess


# 要轉換的文本

text = "明天會更好tomorrow will be better"


# 創建TTS物件

tts = gTTS(text, lang='zh-tw')  # 使用台灣華語語音


# 將語音儲存為檔案

tts.save("output.mp3")


# 播放語音

# os.system("mpg321 output.mp3")  # 需要安裝mpg321或使用其他播放器

# os.system("start wmplayer.exe output.mp3") #windows 10

subprocess.call(["start", "output.mp3"], shell=True) # windows 11


# 刪除暫存檔案

# os.remove("output.mp3")

text to speech , speech to text 參考網頁

 Speechnotes | Speech to Text Online Notepad

Free Text to Speech Online with Realistic AI Voices

2023年10月30日 星期一

成績計算輸出未修版

 d = '''

座號-姓名----國---英--數---社--自-

01 王01美 88 97 89 59 58

02 王02美 59 84 81 56 91

03 王03美 86 92 49 59 82

04 王04美 47 91 52 56 85

05 王05美 86 91 35 95 40

06 王06美 52 98 96 53 27

07 王07美 57 90 90 66 43

08 王08美 97 90 87 62 60

09 王09美 48 87 27 65 77

10 王10美 78 83 21 99 86

11 王11美 51 83 99 58 47

12 王12美 55 83 50 53 34

13 王13美 62 95 95 51 44

14 王14美 51 86 89 72 46

15 王15美 42 81 43 69 39

'''


h = '座號-姓名--國-英--數-社-自--總--平----名次'

d = [[j for j in i.split()] for i in d.splitlines()[2:]]


dd = []

for i in d:

    t = i[:2] + [int(j) for j in i[2:]]

    t.append(sum(t[2:]))

    t.append(sum(t[2:])/5)

    dd.append(t)

    

for i in range(len(dd)):

    ord = 1

    for j in range(len(dd)):

        if dd[i][7]<dd[j][7]:

            ord+=1

    dd[i].append(ord)


print(h)

for i in dd:

    print(*i)



# 執行結果


# 座號-姓名--國-英--數-社-自--總--平----名次

# 01 王01美 88 97 89 59 58 391 156.4 2

# 02 王02美 59 84 81 56 91 371 148.4 3

# 03 王03美 86 92 49 59 82 368 147.2 4

# 04 王04美 47 91 52 56 85 331 132.4 11

# 05 王05美 86 91 35 95 40 347 138.8 6

# 06 王06美 52 98 96 53 27 326 130.4 12

# 07 王07美 57 90 90 66 43 346 138.4 8

# 08 王08美 97 90 87 62 60 396 158.4 1

# 09 王09美 48 87 27 65 77 304 121.6 13

# 10 王10美 78 83 21 99 86 367 146.8 5

# 11 王11美 51 83 99 58 47 338 135.2 10

# 12 王12美 55 83 50 53 34 275 110.0 14

# 13 王13美 62 95 95 51 44 347 138.8 6

# 14 王14美 51 86 89 72 46 344 137.6 9

# 15 王15美 42 81 43 69 39 274 109.6 15

測試用資料

 

座號 姓名
01 王01美 88 97 89 59 58
02 王02美 59 84 81 56 91
03 王03美 86 92 49 59 82
04 王04美 47 91 52 56 85
05 王05美 86 91 35 95 40
06 王06美 52 98 96 53 27
07 王07美 57 90 90 66 43
08 王08美 97 90 87 62 60
09 王09美 48 87 27 65 77
10 王10美 78 83 21 99 86
11 王11美 51 83 99 58 47
12 王12美 55 83 50 53 34
13 王13美 62 95 95 51 44
14 王14美 51 86 89 72 46
15 王15美 42 81 43 69 39




2023年10月19日 星期四

2022-2023 season VEX V5 competition

 https://www.youtube.com/watch?v=c_SLkkOgnpc

VEXcode V5 Blocks - "Device Setup - Controller" Tutorial

 https://www.youtube.com/watch?v=O2hpi0TrYAE&list=PLYhzeRuxhA_pycyVWBs2-Nhb06q7z4z3z

2023年10月18日 星期三

機器人軟腳

 https://www.youtube.com/shorts/-Qe8g2mN_Ak

硬碟1956-2023

 


2023年7月25日 星期二

因數分解

for n in [1500,3500,6000]:

    nb = n

    a = []

    for i in range(2,int(n**0.5)+1):

        while n%i==0:

            a.append(i)   

            n = n /i

    

    out = []

    s = set(a)

    for i in s:

        t = f'{i}^{a.count(i)}'

        out.append(t)

    out = '*'.join(out)

    out = str(nb) + '=' + out

    out = out.replace('^1','')

    print(out)

 



2023年7月12日 星期三

解題數自動統計程式

 d= """
要分析的資料放這裡
"""
d =[i for i in  d.split('\n') if len(i)>0]
d =[i for i in  d if '年' in i and '月' in i and '日' in i and '2023' in i and ':' in i]
# for i in d:
    # print(i)
dd = []
for i in d:
    t = i.split('日 ')
    time1 = t[1]
    t = t[0].split('2023年')
    name1 = t[0]
    date1 = t[1]
    tlist = [name1,date1,time1]
    dd.append(tlist)
nameList = [i[0] for i in dd if len(i[0])>0]
nameSet = set(nameList)
print(len(nameList))
ddd = []
for i in nameSet:
    ddd.append([nameList.count(i),i])
ddd.sort()
ddd.reverse()
for i in ddd:
    print(i[1],':',i[0])
    
# 共166次
# sih yu : 32
# minyu : 27
# matthew0118 : 26
# 掄 : 25
# Rex_Chen : 24
# kadzuki0314 : 21
# jack : 8
# chia : 2
...


2023年7月4日 星期二

桃園國中實作 第2題

 # 桃園國中實作 第2題


# 第二題


# 0代表海

# 1代理陸地


# 給一個坐標,若是0,則輸出0

# 若是1,則與他這個陸地相連的土地有幾個


# 輸入

# 4 5(列,行)

# 1 1坐標

# 00000

# 00000

# 00000

# 00000


# 輸出0


# 4 5

# 1 2

# 0 1 1 0 0

# 0 1 1 0 1

# 0 0 1 0 0

# 0 0 0 0  1


# 輸出5

d = '''

4 5

1 2

0 1 1 0 0

0 1 1 0 1

0 0 1 0 0

0 0 0 0  1

'''

d = d.strip().splitlines()

m,n = map(int,d[0].split())

x,y = map(int,d[1].split())


dd = d[2:]

d = []

for i in dd:

    t = [ int(j) for j in i.split() ]

    d.append(t)

if d[x][y]==0: 

    print(d[x][y])

else:

    rangeList= []

    for i in range(m):

        for j in range(n):

            rangeList.append([i,j])


    visitList = []

    t = [x,y]

  

    tryList = [t]

    while len(tryList)>0:

        t = tryList.pop()

        visitList.append(t)


        tryList = []

        for i in [-1,0,1]:

            for j in [-1,0,1]:

                if [x+i,x+j] in rangeList and  not (i !=0 and j!=0) and [x+i,x+j] not in visitList:

                    tryList.append([x+i,x+j])


        for i in tryList:

            p,q = i[0],i[1]

            if d[p][q]!=0:

                d[p][q]=d[p][q]+1


maxList = []

for i in d:

    maxList.append(max(i))

print(max(maxList))

 

# 執行結果

# 5  

桃園國中實作 第1題

 # 桃園國中實作 第1題


# 第1題

# data

# 3 4


# 1 2 5 4

# 3 2 6 7

# 4 3 7 8輸出

# 求每1列最小值

# 最後一個是最小值中的最大值

# 1

# 2

# 3

# 3



d = '''

3 4


1 2 5 4

3 2 6 7

4 3 7 8

'''

d = [i for i in d.strip().splitlines()]

d = d[2:]

r = []

for i in d:

    t = i.split()

    r.append(min(t))

for i in r:

    print(i)

print(max(r))    

2023年6月19日 星期一

2023-暑假,每日程式上傳區

 每日找2至5個小程式,研究清楚後上傳至這裡,分享給一起學習的夥伴!

每個程式2行以上


成果預計

暑假結束,9月開學時

累積2*60~5*60個程式基礎,功力大增!

有空看看同學上傳的,一起交流,那就是2*60*10~5*60*10了!

大家加油!


2023年6月7日 星期三

用python 程式去python程式註解

 p = '''

a = a.replace('.',' ').replace(',',' ')

a = a.split()

a = [i for i in a if i>'']

# print(a)

# print(len(a))

sa = set(a)

# print(sa)

# print(len(sa))

b = []

for i in sa:

    t = [a.count(i),i.strip().lower()]

    b.append(t)

b.sort()

b.reverse()

b0 = [i[0] for i in b]

# print(*b)

# for i in b:

    # print(i[0],':',i[1])

# for i in b[:30]:

    # print(i)

c = [i for  i in b if i[0]>1 and i[1]>'9']

c0 = [i[0] for i in c]

# for i in c:

    # print(i)

# print(len(c))


# print(sum(b0),sum(c0))

for i in c:

   outline = f'{i[1]:<15} :{i[0]:>10}'

   print(outline)

p = int(sum(c0)/sum(b0) * 10000)/100

print(p)

print(len(c0))

'''

print(p)

p1 = p.splitlines()

# p1 = [i for i in p.split('\n')]

print(len(p1))

for i in p1:

    if len(i) >0:

        t = i

        t = t.strip()

        if t[0]!='#':

            print(i)


# 執行結果

a = a.replace('.',' ').replace(',',' ')

a = a.split()

a = [i for i in a if i>'']

sa = set(a)

b = []

for i in sa:

    t = [a.count(i),i.strip().lower()]

    b.append(t)

b.sort()

b.reverse()

b0 = [i[0] for i in b]

c = [i for  i in b if i[0]>1 and i[1]>'9']

c0 = [i[0] for i in c]

for i in c:

   outline = f'{i[1]:<15} :{i[0]:>10}'

   print(outline)

p = int(sum(c0)/sum(b0) * 10000)/100

print(p)

print(len(c0))

2023年6月6日 星期二

自己寫 split()

 using System;

public class Program

{

public static void Main()

{

string a = "10,20";

string[] b = new string[2];

//b = a.Split(',');

string tem = "";

foreach(char ch in a)

if (ch==',')

{

b[0]=tem;

tem = "";

}

else

tem=tem+ch;

b[1]=tem;

Console.WriteLine(b[0]);

Console.WriteLine(b[1]);

string[] c = new string[2];

c = mySplit(a);

Console.WriteLine(c[0]);

Console.WriteLine(c[1]);

}

public static string[] mySplit(string a)

{

string[] b = new string[2];

string tem = "";

foreach(char ch in a)

if (ch==',')

{

b[0]=tem;

tem = "";

}

else

tem=tem+ch;

b[1]=tem;

return b;

}

}

2023年5月31日 星期三

補考試卷產生器

 #第一版

#d = 'C台灣最高山?(A)阿里山(B)南湖大山(C)玉山(D)八卦山'

#ans = d[0]

#question = d[1:7]

#ansA = d[7:13]

#ansB = d[13:20]

#ansC = d[20:25]

#ansD = d[25:]

#

#q1 = ans + question + ansA + ansB + ansC + ansD

#print(q1)

#ans = 'A'

#q2 = ans + question + ansC + ansB + ansA + ansD

#print(q2)

#執行結果

#C台灣最高山?(A)阿里山(B)南湖大山(C)玉山(D)八卦山

#A台灣最高山?(C)玉山(B)南湖大山(A)阿里山(D)八卦山


##第二版

#d = 'C台灣最高山?(A)阿里山(B)南湖大山(C)玉山(D)八卦山'

#ans = d[0]

#question,ansA,ansB,ansC,ansD = d[1:].split('(')

#ansA = ansA[2:]

#ansB = ansB[2:]

#ansC = ansC[2:]

#ansD = ansD[2:]

#

#q1 = ans + question +'(A)'+ ansA +'(B)'+ ansB +'(C)'+ ansC +'(D)'+ ansD

#print(q1)

#ans = 'A'

#q2 = ans + question +'(A)'+ ansC +'(B)'+ ansB +'(C)'+ ansA +'(D)'+ ansD

#print(q2)


##第三版

##d = 'C台灣最高山?(A)阿里山(B)南湖大山(C)玉山(D)八卦山'

##d = 'B台灣最高山?(A)阿里山(B)玉山(C)南湖大山(D)八卦山'

##d = 'A台灣最高山?(A)玉山(B)阿里山(C)南湖大山(D)八卦山'

#d = 'D台灣最高山?(A)八卦山(B)阿里山(C)南湖大山(D)玉山'

#ans = d[0]

#question,ansA,ansB,ansC,ansD = d[1:].split('(')

#ansA = ansA[2:]

#ansB = ansB[2:]

#ansC = ansC[2:]

#ansD = ansD[2:]

#

#q1 = ans + question +'(A)'+ ansA +'(B)'+ ansB +'(C)'+ ansC +'(D)'+ ansD

#print(q1)

#if ans=='D':

#    ans = 'C'

#    q2 = ans + question +'(A)'+ ansA +'(B)'+ ansB +'(C)'+ ansD +'(D)'+ ansC

#elif ans=='C':

#    ans = 'A'

#    q2 = ans + question +'(A)'+ ansC +'(B)'+ ansB +'(C)'+ ansA +'(D)'+ ansD

#elif ans=='B':

#    ans = 'D'

#    q2 = ans + question +'(A)'+ ansA +'(B)'+ ansD +'(C)'+ ansC +'(D)'+ ansB

#elif ans=='A':

#    ans = 'B'

#    q2 = ans + question +'(A)'+ ansB +'(B)'+ ansA +'(C)'+ ansC +'(D)'+ ansD

#print(q2)


#第四版

# dd = []

# d = 'C台灣最高山?(A)阿里山(B)南湖大山(C)玉山(D)八卦山'

# dd.append(d)

# d = 'B台灣最高山?(A)阿里山(B)玉山(C)南湖大山(D)八卦山'

# dd.append(d)

# d = 'A台灣最高山?(A)玉山(B)阿里山(C)南湖大山(D)八卦山'

# dd.append(d)

# d = 'D台灣最高山?(A)八卦山(B)阿里山(C)南湖大山(D)玉山'

# dd.append(d)


# for d in dd:

#     ans = d[0]

#     question,ansA,ansB,ansC,ansD = d[1:].split('(')

#     ansA = ansA[2:]

#     ansB = ansB[2:]

#     ansC = ansC[2:]

#     ansD = ansD[2:]

    

#     q1 = ans + question +'(A)'+ ansA +'(B)'+ ansB +'(C)'+ ansC +'(D)'+ ansD

#     print(q1)

#     if ans=='D':

#         ans = 'C'

#         q2 = ans + question +'(A)'+ ansA +'(B)'+ ansB +'(C)'+ ansD +'(D)'+ ansC

#     elif ans=='C':

#         ans = 'A'

#         q2 = ans + question +'(A)'+ ansC +'(B)'+ ansB +'(C)'+ ansA +'(D)'+ ansD

#     elif ans=='B':

#         ans = 'D'

#         q2 = ans + question +'(A)'+ ansA +'(B)'+ ansD +'(C)'+ ansC +'(D)'+ ansB

#     elif ans=='A':

#         ans = 'B'

#         q2 = ans + question +'(A)'+ ansB +'(B)'+ ansA +'(C)'+ ansC +'(D)'+ ansD

#     print(q2)

# 執行結果

# A台灣最高山?(A)玉山(B)南湖大山(C)阿里山(D)八卦山

# B台灣最高山?(A)阿里山(B)玉山(C)南湖大山(D)八卦山

# D台灣最高山?(A)阿里山(B)八卦山(C)南湖大山(D)玉山

# A台灣最高山?(A)玉山(B)阿里山(C)南湖大山(D)八卦山

# B台灣最高山?(A)阿里山(B)玉山(C)南湖大山(D)八卦山

# D台灣最高山?(A)八卦山(B)阿里山(C)南湖大山(D)玉山

# C台灣最高山?(A)八卦山(B)阿里山(C)玉山(D)南湖大山


# #第五版

# ddd = '''

# C台灣最高山?(A)阿里山(B)南湖大山(C)玉山(D)八卦山

# B台灣最高山?(A)阿里山(B)玉山(C)南湖大山(D)八卦山

# A台灣最高山?(A)玉山(B)阿里山(C)南湖大山(D)八卦山

# D台灣最高山?(A)八卦山(B)阿里山(C)南湖大山(D)玉山

# '''

# dd = ddd.strip().splitlines()


# for d in dd:

#     ans = d[0]

#     question,ansA,ansB,ansC,ansD = d[1:].split('(')

#     ansA = ansA[2:]

#     ansB = ansB[2:]

#     ansC = ansC[2:]

#     ansD = ansD[2:]

    

#     q1 = ans + question +'(A)'+ ansA +'(B)'+ ansB +'(C)'+ ansC +'(D)'+ ansD

#     # print(q1)

#     if ans=='D':

#         ans = 'C'

#         q2 = ans + question +'(A)'+ ansA +'(B)'+ ansB +'(C)'+ ansD +'(D)'+ ansC

#     elif ans=='C':

#         ans = 'A'

#         q2 = ans + question +'(A)'+ ansC +'(B)'+ ansB +'(C)'+ ansA +'(D)'+ ansD

#     elif ans=='B':

#         ans = 'D'

#         q2 = ans + question +'(A)'+ ansA +'(B)'+ ansD +'(C)'+ ansC +'(D)'+ ansB

#     elif ans=='A':

#         ans = 'B'

#         q2 = ans + question +'(A)'+ ansB +'(B)'+ ansA +'(C)'+ ansC +'(D)'+ ansD

#     print(q2)

# # 執行結果


# #第六版

# # ddd = '''

# # C台灣最高山?(A)阿里山(B)南湖大山(C)玉山(D)八卦山

# # B台灣最高山?(A)阿里山(B)玉山(C)南湖大山(D)八卦山

# # A台灣最高山?(A)玉山(B)阿里山(C)南湖大山(D)八卦山

# # D台灣最高山?(A)八卦山(B)阿里山(C)南湖大山(D)玉山

# # '''

# f1 = open("q10.data",encoding='utf-8')

# dd = f1.readlines()

# dd = [i[:-1] for i in dd]

# # print(dd)

# # dd = ddd.strip().splitlines()


# for d in dd:

#     ans = d[0]

#     question,ansA,ansB,ansC,ansD = d[1:].split('(')

#     ansA = ansA[2:]

#     ansB = ansB[2:]

#     ansC = ansC[2:]

#     ansD = ansD[2:]

    

#     q1 = ans + question +'(A)'+ ansA +'(B)'+ ansB +'(C)'+ ansC +'(D)'+ ansD

#     # print(q1)

#     if ans=='D':

#         ans = 'C'

#         q2 = ans + question +'(A)'+ ansA +'(B)'+ ansB +'(C)'+ ansD +'(D)'+ ansC

#     elif ans=='C':

#         ans = 'A'

#         q2 = ans + question +'(A)'+ ansC +'(B)'+ ansB +'(C)'+ ansA +'(D)'+ ansD

#     elif ans=='B':

#         ans = 'D'

#         q2 = ans + question +'(A)'+ ansA +'(B)'+ ansD +'(C)'+ ansC +'(D)'+ ansB

#     elif ans=='A':

#         ans = 'B'

#         q2 = ans + question +'(A)'+ ansB +'(B)'+ ansA +'(C)'+ ansC +'(D)'+ ansD

#     print(q2)

# # 執行結果

# A台灣最高山?(A)玉山(B)南湖大山(C)阿里山(D)八卦山

# D台灣最高山?(A)阿里山(B)八卦山(C)南湖大山(D)玉山

# B台灣最高山?(A)阿里山(B)玉山(C)南湖大山(D)八卦山

# C台灣最高山?(A)八卦山(B)阿里山(C)玉(D)南湖大山


# #第七版

# f1 = open("q10.data",encoding='utf-8')

# dd = f1.readlines()

# dd = [i[:-1]  if i[-1]=='\n' else i for i in dd]


# for d in dd:

#     # print(d)

#     ans = d[0]

#     question,ansA,ansB,ansC,ansD = d[1:].split('(')

#     ansA = ansA[2:]

#     ansB = ansB[2:]

#     ansC = ansC[2:]

#     ansD = ansD[2:]

    

#     q1 = ans + question +'(A)'+ ansA +'(B)'+ ansB +'(C)'+ ansC +'(D)'+ ansD

#     # print(q1)

#     if ans=='D':

#         ans = 'C'

#         q2 = ans + question +'(A)'+ ansA +'(B)'+ ansB +'(C)'+ ansD +'(D)'+ ansC

#     elif ans=='C':

#         ans = 'A'

#         q2 = ans + question +'(A)'+ ansC +'(B)'+ ansB +'(C)'+ ansA +'(D)'+ ansD

#     elif ans=='B':

#         ans = 'D'

#         q2 = ans + question +'(A)'+ ansA +'(B)'+ ansD +'(C)'+ ansC +'(D)'+ ansB

#     elif ans=='A':

#         ans = 'B'

#         q2 = ans + question +'(A)'+ ansB +'(B)'+ ansA +'(C)'+ ansC +'(D)'+ ansD

#     print(q2)

# # 執行結果

# A台灣最高山?(A)玉山(B)南湖大山(C)阿里山(D)八卦山

# D台灣最高山?(A)阿里山(B)八卦山(C)南湖大山(D)玉山

# B台灣最高山?(A)阿里山(B)玉山(C)南湖大山(D)八卦山

# C台灣最高山?(A)八卦山(B)阿里山(C)玉山(D)南湖大山


# #第八版

# # q10.data

# # C台灣最高山?(A)阿里山(B)南湖大山(C)玉山(D)八卦山

# # A哪一個山在嘉義?(A)阿里山(B)玉山(C)南湖大山(D)八卦山

# # D哪一個山在彰化?(A)玉山(B)阿里山(C)南湖大山(D)八卦山

# # C哪一個山在宜蘭?(A)八卦山(B)阿里山(C)南湖大山(D)玉山

# f1 = open("q10.data",encoding='utf-8')

# dd = f1.readlines()

# dd = [i[:-1]  if i[-1]=='\n' else i for i in dd]


# for d in dd:

#     ans = d[0]

#     dlist = d[1:].split('(')

#     question = dlist[0]

#     ansList = dlist[1:]

#     ansList = [i[2:] for i in ansList ]

#     ansText = ansList['ABCD'.index(ans)]

#     ansList.sort()

#     newAns = 'ABCD'[ansList.index(ansText)]

#     q2 = newAns + question +'(A)'+ ansList[0] +'(B)'+ ansList[1] +'(C)'+ ansList[2] +'(D)'+ ansList[3]

#     print(q2)

# # 執行結果

# # C台灣最高山?(A)八卦山(B)南湖大山(C)玉山(D)阿里山

# # D哪一個山在嘉義?(A)八卦山(B)南湖大山(C)玉山(D)阿里山

# # A哪一個山在彰化?(A)八卦山(B)南湖大山(C)玉山(D)阿里山

# # B哪一個山在宜蘭?(A)八卦山(B)南湖大山(C)玉山(D)阿里山


#第九版

# q10.data

# C台灣最高山?(A)阿里山(B)南湖大山(C)玉山(D)八卦山

# A哪一個山在嘉義?(A)阿里山(B)玉山(C)南湖大山(D)八卦山

# D哪一個山在彰化?(A)玉山(B)阿里山(C)南湖大山(D)八卦山

# C哪一個山在宜蘭?(A)八卦山(B)阿里山(C)南湖大山(D)玉山

f1 = open("q10.data",encoding="utf-8")

f2 = open("q10.out","w",encoding="utf-8")

dd = f1.readlines()

dd = [i[:-1]  if i[-1]=='\n' else i for i in dd]


for d in dd:

    ans = d[0]

    dlist = d[1:].split('(')

    question = dlist[0]

    ansList = dlist[1:]

    ansList = [i[2:] for i in ansList ]

    ansText = ansList['ABCD'.index(ans)]

    ansList.sort()

    newAns = 'ABCD'[ansList.index(ansText)]

    q2 = newAns + question +'(A)'+ ansList[0] +'(B)'+ ansList[1] +'(C)'+ ansList[2] +'(D)'+ ansList[3]

    print(q2)

    f2.write(q2+'\n')

# 執行結果 q10.out

# C台灣最高山?(A)八卦山(B)南湖大山(C)玉山(D)阿里山

# D哪一個山在嘉義?(A)八卦山(B)南湖大山(C)玉山(D)阿里山

# A哪一個山在彰化?(A)八卦山(B)南湖大山(C)玉山(D)阿里山

# B哪一個山在宜蘭?(A)八卦山(B)南湖大山(C)玉山(D)阿里山

2023年2月24日 星期五

2023年1月4日 星期三

進位轉換

 def two2ten(a):

# a = '10101'

    b = [int(i) for i in a]

    # print(b)

    c = []

    s = 0

    k =len(a)-1

    for i in b:

        s = s + i*2**k

        k-=1

    return s


def ten2two(n):

# n = 18

    if n==0 :return '0'

    s = ''

    while n>=1:

        s = str(n%2) + s 

        n = n//2

    return s


for i in ['1','10','11','101','10111011']:

    print(f'{i} -> {two2ten(i)}')

for i in range(20):

    print(i,ten2two(i))