-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinear_equation.py
More file actions
76 lines (71 loc) · 2.04 KB
/
Copy pathlinear_equation.py
File metadata and controls
76 lines (71 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# input format ax+b=c or c=b+ax
# Examples: -23.5x + 33.7 = 234 456 = -33.3 + 54x
eq = str(input())
a = []
b = []
c = []
plus = []
minus = []
print(eq, '\n') # '\n' voor extra lege regel
# Maak list met cijfers 0 tot lengte van de input:
eq_l = list(range(len(eq)))
# delete spaces
for i in eq_l:
eq_l[i] = eq[i]
count_space = eq_l.count(' ')
for i in range(count_space):
eq_l.remove(' ')
equal = eq_l.index('=')
to_x = eq_l.index('x')
# # function for find coeffs
# def section(i, list_1, section_l, range_1, range_2):
# for i in range(range_1, range_2):
# try:
# float((list_1[i]))
# except ValueError:
# if list_1[i] == '-':
# section_l.append(list_1[i])
# elif list_1[i] == '.':
# section_l.append(list_1[i])
# else:
# section_l.append(list_1[i])
#
#
# # if ax+b=c
# if equal > to_x:
# section(i, eq_l, a, 0, to_x)
# section(i, eq_l, b, to_x, equal)
# section(i, eq_l, c, equal, len(eq_l))
#
# A = float(''.join(a))
# B = float(''.join(b))
# C = float(''.join(c))
# print('a=', A, ' b=', B, ' c=', C)
# print('x=', (C - B) / A)
# # if c=b+ax worked hard on it
# else:
# section(i, eq_l, c, 0, equal)
#
# for i in range(equal):
# eq_l.pop(0)
#
# for i in range(len(eq_l)):
# if eq_l[i] == '+':
# plus.append((eq_l.index('+', i, len(eq_l))))
# elif eq_l[i] == '-':
# minus.append((eq_l.index('-', i, len(eq_l))))
#
# if len(plus) == 1 and len(minus) <= 1:
# section(i, eq_l, b, 0, eq_l.index('+'))
# section(i, eq_l, a, eq_l.index('+'), len(eq_l))
# elif len(minus) == 2:
# section(i, eq_l, b, 0, minus[1])
# section(i, eq_l, a, minus[1], len(eq_l))
# else:
# section(i, eq_l, b, 0, eq_l.index('-'))
# section(i, eq_l, a, eq_l.index('-'), len(eq_l))
# C = float(''.join(c))
# B = float(''.join(b))
# A = float(''.join(a))
# print('a=', A, ' b=', B, ' c=', C)
# print('x=', (C - B) / A)