1樓:夢囈罒幻羽
import re
str1="123456"
lis1=re.findall("^\d\d",str1)if 0<=int(list[0])<=24:
if 0<=int(list[1])<=60:
if 0<=int(list[2])<=60:
print ("%d時%d分%d秒
源"%(int(list[0]),int(list[1]),int(list[2])))
else:
print("秒cc錯誤")
else:
print("分bb錯誤")
else:
print("小時aa錯誤")
思路就是這樣,適當修改就可以了
求解 python 練習題 5
2樓:野人拆
import string
def makewordlist(input_file, output_file):
table = string.maketrans("", "")try:
word_list = dict()
for line in open(input_file, 'r'):
line = line.translate(table, string.punctuation).rstrip('\r\n').split(' ')
for word in line:
if not word in word_list:
word_list[word] = 1
else:
word_list[word] += 1
f = open(output_file, 'w')for k,v in word_list.items():
line = '%s %s\r\n' % (k,v)f.write(line)
except:
print input_file,'not exist'
makewordlist('input.txt', 'output.txt')
python習題求解答
3樓:灰色
重複讀取資料寫個while迴圈就行了
**為:
arr =
num = 0
sum = 0
while 1:
val = input('請輸入乙個數版')try:
if val == 'done':
for i in arr:
sum = sum + float(i)
print('總和為:' + str(sum))print('輸入個
求解python練習題,求解python練習題
import string def makewordlist input file,output file table string.maketrans try word list dict for line in open input file,r line line.translate tabl...
Python有關loop的問題,python 如何用loop解決這個問題
def i agic square rows len square total sum square 1 total3 total4 0 for row in range rows if sum square row total return false for col in range rows ...
執行python時提示無效語法,Python為什麼顯示無效語法
簡單看了下,if和elif沒對齊,縮排不對,再乙個,用了while迴圈怎能沒有break和continue呢 把import ivhp換這個試試,from ivhp import 錯誤的原因是pyshell 0沒有呼叫到ivhp,語法不對。python為什麼顯示無效語法 紅色標記的 上面一行 末尾少...