求python大神帮我看一下,这个怎么搞
python的问题 input输入的字符串,要变成数字,要转换一下使用就可以。 如果还没学到正则表达式,就用isdigit()方法和join()方法,写个循环洗一下字符串 # *-* coding:utf8 *-*def intinstr(nn):
n = ''
for i in nn:# 遍历这个字符串
if i.isnumeric(): #如果是数字就提取出来
n += i
return int(n) # 转换成int返回
n1 = intinstr(input())
n2 = intinstr(input())
print("%d" % (n1 + n2))# 输出结果
"""
1kkk2jjhhhu5
4jkjllkn5lkjioj6
581
"""
楼主,看下是不是这样的 可以考虑findall()函数配合正则表达式,re.findall('\d',字符串),然后再拼接 s1=input()
s2=input()
n1=""
n2=""
for i in s1:
if 57>=ord(i)>=48:
n1+=(str)(i)
for i in s2:
if 57>=ord(i)>=48:
n2+=(str)(i)
print((int)(n1)-(int)(n2)) # -*- coding: utf-8 -*-
import re
strs1 = input()
strs2 = input()
news1 = re.findall(r'\d',strs1)
num1 = int(''.join(news1))
news2 = re.findall(r'\d',strs2)
num2 = int(''.join(news2))
see = "{:d}-{:d}={:d}".format(num1,num2,num1-num2)
print(see)
# -*- coding: utf-8 -*-
import re
strs1 = input()
strs2 = input()
news1 = re.findall(r'\d',strs1)
num1 = int(''.join(news1))
news2 = re.findall(r'\d',strs2)
num2 = int(''.join(news2))
see = "{:d}-{:d}={:d}".format(num1,num2,num1-num2)
print(see) 本帖最后由 UPC 于 2020-4-10 16:06 编辑
俺也是刚学{:1_908:}{:1_926:} 之前判断把'0'漏掉了
def return_num(strs):
a = ''
for str in strs:
if str >= '0' and str <= '9':
a += str
return int(a)
ma1 = return_num(input())
ma2 = return_num(input())
print('{}'.format(ma1 - ma2))
gdgdg5trht656hjgdgdg
gddgd55jsdsh58555gfhds
-5552899 GMCN 发表于 2020-4-10 10:50
# *-* coding:utf8 *-*
def intinstr(nn):
谢谢谢谢
页:
[1]
2