貨幣轉換python輸入字母在數字後面
Ⅰ python 將數字轉換成對應的英文數字
def
chartonum(c):
....if
c.isalpha():
........return
ord(c)
....else:
........return
'參數只能是英文字母'
(把.換成空格)
Ⅱ python 輸出特定字元串後面的數字
加個零寬斷言就行了,python的零寬斷言不支持長度不固定的表達式,所以需要將\s*移動到括弧外邊,用float()函數對數據進行處理就行了,float()函數可以處理字元串中的\s*等字元。
p
=
re.compile('(?<=cpu:)\s*\d*\.\d*')
f2
=
open('time.txt','r').readline()
print
list(map(float,p.findall(f2)))
結果如下,我用的是python3,所以print函數有一點點小變化。
>>>
f2
=
'enc
:0.088452
ms,cpu:
0.004
dec
:0.020126
ms,cpu:
0.001'
>>>
p
=
re.compile('(?<=cpu:)\s*\d*\.\d*')
>>>
print(list(map(float,p.findall(f2))))
[0.004,
0.001]
>>>
Ⅲ 為什麼在python中把輸入數字的地方輸入字母後有bug
什麼bug?說來聽聽。。。
Ⅳ 求python代碼。貨幣轉換人民幣對美元。格式為: 人民幣:20 美元:xxx
def func(money):
return f'人民幣:20美元:{money*20}'
不大懂你的意思,但是感覺很簡單23333,不知道你要的效果,你最好舉個例子,比如輸入什麼,輸出什麼
Ⅳ python 輸入一個字母 如果它是一個小寫英文字母 則把它轉換為對應的大寫字母輸出
char1=input("請輸入一個小寫英文字母:");
if(ord(char1)>=ord('a')andord(char1)<=ord('z')):
print(char1.upper());
else:
print("不是小寫字母!");
Ⅵ python怎麼實現輸入一個字母就把對應的數字輸出來
有兩種方法,一種是直接做一個26個字母的字典,然後print(dict[x]),另一種是你可以將字母直接轉換成ascll碼然後print(ord(x)-97+1) a的ascll碼為97
Ⅶ python中將字母轉換為數字
dic={'a':2,'b':6}
sum_num=0
while1:
enter=raw_input('Enter:')
ifenter=='exit':
break
ifdic.has_key(enter):
sum_num+=dic[enter]
else:
print'EnterError'
Ⅷ python中把各個字母對應的數字加起來然後把得到的結果各個數字相加 加到只剩個位
#s即輸入的字元串(僅包含小寫英文字母),如果要計算的是所有英文字母,輸入"abcdefg..."
defcal(s):
arr=bytearray(s)
cnt=0
base=bytearray('a')[0]
forbtinarr:
cnt+=bt-base+1
basedg=bytearray('0')[0]
whilecnt>9:
scnt=bytearray(str(cnt))
cnt=0
forbtinscnt:
cnt+=bt-basedg
#或者
"""
tmp=0
whilecnt>0:
tmp+=cnt%10
cnt/=10
cnt=tmp
"""
returncnt
Ⅸ Python輸入一行任意大小寫字母、數字和符號,回車結束
先用正則表達提取,然後聚合去重,在轉化列表,在降序輸出,這樣輸出是列表。在轉化字元串
importre
a=input('輸入:')
b=''.join(sorted(list(set(re.findall('d',a))),reverse=True))
c=''.join(sorted(list(set(re.findall('W',a))),reverse=True))
d=''.join(sorted(list(set(re.findall('[a-z]',a))),reverse=True))
e=''.join(sorted(list(set(re.findall('[A-Z]',a))),reverse=True))
print('{0} {1} {2} {3} '.format(b,c,d,e))
Ⅹ 貨幣轉換的python程序代碼,哪裡錯了,請大神指點
發出錯誤提示來看看。