1.參考攻略完成 "凱歌地牢" 1-22
2.走出凱哥地牢後開始挑戰 "邊遠地區的森林"
import pyautogui
pyautogui.click(30,10) #點擊座標 30,10
pyautogui.press('up') #按下'上'鍵
for i in range(60):#迴圈:重複60次,i=0~59
p=pyautogui.position() #取得座標放進變數p裡面
print(p) #印出p (目前滑座標)
pyautogui.time.sleep(1) #等待1秒
#pix = pyautogui.pixel(100, 200)
#pyautogui.position()
#coding:utf8
import os, sys
from imp import reload
reload(sys)
from win32com.client import Dispatch, constants, gencache
def doc2pdf(sourceF,tartgetF):
#sourceF = 'D:\\1.doc'
#tartgetF = 'D:\\1.pdf'
print(sourceF,' ==> ',tartgetF)
# enable python COM support for Word 2007
# this is generated by: makepy.py -i "Microsoft Word 12.0 Object Library"
gencache.EnsureModule('{00020905-0000-0000-C000-000000000046}', 0, 8, 4)
# 開始轉換
w = Dispatch("Word.Application")
try:
doc = w.Documents.Open(sourceF, ReadOnly=1)
doc.ExportAsFixedFormat(tartgetF, constants.wdExportFormatPDF, \
Item=constants.wdExportDocumentWithMarkup,
CreateBookmarks=constants.wdExportCreateHeadingBookmarks)
except: print('exception')
finally: w.Quit(constants.wdDoNotSaveChanges)
if os.path.isfile(tartgetF):print('translate success')
else:print('translate fail')
desktop = os.path.join(os.path.join(os.path.expanduser('~')), 'Desktop')
print('DOC/DOCX to PDF batch converter . by K.Y. Lee (c) 2020 All Rights Reserved')
folder = input('enter the target folder of MS doc/docx files on YOUR Desktop\n輸入欲轉換之word文件資料夾名稱(桌面上)[不需完整路徑]:')
DIR = desktop+'\\'+folder+"\\"
files = os.listdir(DIR)
for f in files:
ii = f.find('.doc')
if ii>0:
doc2pdf(DIR+f,DIR+f[:ii]+'.pdf')

int n;
while(scanf("%d",&n) != EOF)
{
//...主程式...
}
while True:
try:a=input()
except:break #過濾掉 EOFError,讀到EOF後直接跳出迴圈
if not a:break #輸入空字串時跳出迴圈
print('hello,',a)
while True:
try:
#用字串內建的 split() 函式
#將字串做分割並將結果回傳給 a,b
a,b=input().split()
except: break
if not a:break
print(int(a)+int(b))
R=['普通','吉','大吉']
while True:
try:
M,D=input().split()
except: break
S=(int(M)*2+int(D))%3
print(R[S])
#西元年被4整除且不被100整除,或被400整除者即為閏年
while True:
try:
Y=int(input())
except: break
if (Y%4==0 and Y%100!=0)or Y%400==0 :
print('閏年')
else :
print('平年')
n=int(input())
for i in range(n):
L=input().split()
#A=[int(L[0]),int(L[1]),int(L[2]),int(L[3])]
A= list(map(int,L))#一個將 L 串列中的元素取int的簡潔方法
if A[1]-A[0] == A[2]-A[1] : #等差
A.append(A[3]+A[2]-A[1])
else: #等比
A.append(A[3]*int(A[2]/A[1]))
#把 A 串列中的元素塞到空字串R裡面,並用空白字元隔開
R=""
for a in A:
r=str(a) #別忘了 A中的元素已被轉換成int了,要做字串運算的話要再轉換回來
R=R+r+" "
print(R.strip())#用字串內建strip函式將頭尾多餘的空白字元刪除
#為什麼只要勾選「我不是機器人」,Google 就知道你不是機器人
#https://buzzorange.com/techorange/2017/09/13/captcha-and-recaptcha/
#台鐵訂票系統
#https://tip.railway.gov.tw/tra-tip-web/tip/tip001/tip121/query
import pyautogui as ag
import pyperclip as clip
import random as rnd
ID='A195077385'
Departure ='台南'
Destination = '台北'
Date = "2019/05/19"
startTime = "13"
endTime = "14"
Num=2
# 在螢幕上找到和影像檔 f 相似度大於 c 的位址,並移動過去
# dx,dy 代表實際目標的水平修正量及垂直修正量
def move2Pic(f,c=0.95,dx=0,dy=0,dur=0):
try:
x,y=ag.locateCenterOnScreen(f,confidence=0.95)
ag.moveTo(x+dx,y+dy,dur)
return True
except:pass
return False
# 在螢幕上找到和影像檔 f 相似度大於 c 的位址,並移動過去點一下
# dx,dy 代表實際目標的水平修正量及垂直修正量
def clickPic(f,c=0.95,dx=0,dy=0,dur=0):
if move2Pic(f,c,dx,dy,dur):
ag.click()
return True
else: return False
def R(s=0.5,e=0.9):#取亂數,預設0.5~0.914之間
return rnd.uniform(0.5,0.9)
def copyPast(Text):#將文字放到剪貼簿並按下 ctrl+v
clip.copy(Text)
ag.hotkey('ctrl','v')
主程式clickPic('enterID.png',dy=30,dur=R())#輸入身份証
for i in range(8):ag.scroll(25)
copyPast(ID)
ag.time.sleep(R())
clickPic('Departure.png',dy=30,dur=R())#輸入出發站
copyPast(Departure)
ag.time.sleep(R())
clickPic('Destination.png',dy=30,dur=R())#輸入抵達站
copyPast(Destination)
ag.time.sleep(R())
for i in range(Num-1):#選擇數量
clickPic('plus.png',dur=R())
ag.time.sleep(R())
clickPic('asTime.png',dur=R()) #依時段
for i in range(20):ag.scroll(-25)
#連點三下全選的日期
move2Pic('Date.png',dx=10,dy=30)
ag.doubleClick()
ag.click()
ag.time.sleep(R())
copyPast(Date) #貼上目標日期
ag.time.sleep(R())
for i in range(4):
ag.press('tab')
ag.time.sleep(R())
ag.typewrite(startTime,R(0.1,0.5))
ag.time.sleep(R())
ag.press('tab')
ag.time.sleep(R())
ag.typewrite(endTime,R(0.1,0.5))
move2Pic('imNotRobot.png',dx=-50,dur=R())
ag.time.sleep(R())
#ag.click()
#move2Pic('getTicket.png',dx=-50,dur=rnd.uniform(0.5,0.9))

import queue
In = input().strip()
while In!="":# while not In
n= int(In)
p=[-1]*(n+1) #p[i]=j,表示i的雙親為j
d=[0]*(n+1) #紀錄節點深度
num=[0]*(n+1) #紀錄節點的子節點個數,子節點計算過後就減1
t =queue.Queue() #儲存待走訪之節點
for i in range(1,n+1): #為方便觀察從索引 1 開始放置元素
#line = list(map(int,f.readline().split()) )
line = list(map(int,input().split()) ) #讀入一行後轉換為 int
k = line[0]
num[i] = k #節點 i 的子節點個數
if k == 0:
t.put(i) #葉節點先納入待走訪的節點
else:
for j in line[1:]:
p[j] = i #使用陣列p紀錄 j 的parent為i
i = 0
node = 0
while True:
node = t.get() #取出待走訪之節點
if p[node] == -1:break #沒有父節點代表它是根節點==>結束迴圈
d[p[node]]=max(d[p[node]],d[node]+1) #葉節點深度+1 和 已記錄之深度取大者作為本節點深度
num[p[node]]=num[p[node]]-1 #父節點底下未走謗過的子節點數目減1
if num[p[node]] == 0: #當所有子節點都走訪過時,將該父節點納入待走訪之節點
t.put(p[node])
print(node)#最後一個從t取出的就是根節點
print(sum(d))#最後一個從t取出的就是根節點
try:In = input().strip()
except EOFError:break
#Speech Recognition (語音轉文字)
import speech_recognition as sr
r = sr.Recognizer()
print('請對麥克風說話...')
with sr.Microphone() as source:
audio = r.listen(source)
textZh = r.recognize_google(audio,language='zh-TW')
print(textZh)
#google翻譯
from googletrans import Translator
ts = Translator()
textJa = ts.translate(textZh,dest='ja').text
print(textJa)
#google Text to Speech (文字轉語音)
from gtts import gTTS
tts=gTTS(text=textJa, lang='ja')
import tempfile
filename = tempfile.NamedTemporaryFile().name+'.mp3'
tts.save(filename)
#播放音TSO
from pygame import mixer
mixer.init()
mixer.music.load(filename)
mixer.music.play()
台灣