货币转换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程序代码,哪里错了,请大神指点
发出错误提示来看看。