标签:style print dal exception == eva val except find
1 import re 2 3 num_one = ‘(98798465*5465+4654-5464*45616846+84654)‘ 4 print(eval(num_one)) 5 6 total = 0 7 print(num_one) 8 while True: 9 try: 10 a = re.search(‘\((\-)(\d+)‘, num_one) 11 if a: 12 num_one = num_one.replace(a.group(1), ‘‘, 1) 13 num_one = num_one.replace(‘)‘, ‘‘) 14 num_one = num_one + str(-2 * int(a.group(2))) + ‘)‘ 15 print(num_one) 16 first = re.search(‘[*|/]‘, num_one) 17 print(first.group()) 18 try: 19 if first.group() == ‘*‘: 20 num1 = re.findall(‘(\d+)\*(\d+)‘, num_one) 21 total1 = int(num1[0][0]) * int(num1[0][1]) 22 # total1 = int(num1[0][0]) * int(num1[0][1]) 23 total += total1 24 num_one = re.sub(‘\d+\*\d+‘, str(total1), num_one, 1) 25 print(num_one, ‘11111‘) 26 elif first.group() == ‘/‘: 27 num1 = re.findall(‘(\d+)/(\d+)‘, num_one) 28 total1 = int(num1[0][0]) / int(num1[0][1]) 29 total += total1 30 num_one = re.sub(‘\d+\/\d+‘, str(total1), num_one, 1) 31 print(num_one) 32 except Exception as f: 33 break 34 except Exception as d: 35 break 36 while True: 37 try: 38 first = re.search(‘\d+([+|-])‘, num_one) 39 print(first.group(1)) 40 try: 41 if first.group(1) == ‘+‘: 42 num1 = re.findall(‘(\d+)\+(\d+)‘, num_one) 43 total1 = int(num1[0][0]) + int(num1[0][1]) 44 # total1 = int(num1[0][0]) * int(num1[0][1]) 45 total += total1 46 num_one = re.sub(‘\d+\+\d+‘, str(total1), num_one, 1) 47 print(num_one, ‘222222‘) 48 elif first.group(1) == ‘-‘: 49 num1 = re.findall(‘(\d+)\-(\d+)‘, num_one) 50 total1 = int(num1[0][0]) - int(num1[0][1]) 51 total += total1 52 if total1 < 0 and len(re.findall(‘\d+‘, num_one)) > 2: 53 num_one = re.sub(‘\d+\-\d+‘, str(abs(total1)), num_one, 1) 54 num_one = num_one.replace(‘)‘, ‘‘) 55 num_one = num_one + str(total1 * 2) + ‘)‘ 56 elif total1 < 0 and len(re.findall(‘\d+‘, num_one)) <= 2: 57 num_one = str(total1) 58 break 59 else: 60 num_one = re.sub(‘\d+\-\d+‘, str(total1), num_one, 1) 61 print(num_one, ‘33333‘) 62 except Exception as f: 63 break 64 except Exception as d: 65 break 66 num_one = re.sub(‘[()]‘, ‘‘, num_one) 67 print(num_one) 68 输出: 69 290683253989 70 290683253989
标签:style print dal exception == eva val except find
原文地址:https://www.cnblogs.com/ch2020/p/12412014.html