-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalculatorforprint.py
170 lines (118 loc) · 2.91 KB
/
Calculatorforprint.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# A python code to realize a calculator from bits like in Verilog. Looking at this code we can design a calculator from Nand gates writing in Verilog.
x='25;
y=input();
product=int(x[1])*int(y[1])+10*(int(x[0])*int(y[1])+int(x[1])*int(y[0]))+int(x[0])*int(y[0])*100
add=int(x[1])+int(y[1])+10*(int(x[0])+int(y[0]))
sub=int(x[1])-int(y[1])+10*(int(x[0])-int(y[0]))
print('Product ', product)
print('Sum ',add)
print('Subtraction ',sub)
print('Input single digit number to divide first')
z=input()
ha=1;
j=0;
while ha:
r=int(x[1])+10*int(x[0])-j*int(z[0]);
if(r<int(z[0])):
ha=0;
j=j+1;
j=j-1;
ha=1;
h=0;
while ha:
r2=r*10-h*int(z[0]);
if(r2<int(z[0])):
ha=0;
h=h+1;
h=h-1;
print('division ',j,'.',h)
print('Input 3 digit number to find the square root')
sq=input();
ha=1;
a=0;
while ha:
luv=int(sq[0])*100+int(sq[1])*10+int(sq[2])-100*a*a;
a=a+1;
if luv<0:
ha=0;
a=a-2;
ha=1;
b=0;
while ha:
luv2=int(sq[0])*100+int(sq[1])*10+int(sq[2])-100*a*a-(20*a+b)*b;
b=b+1;
if luv2<0:
ha=0;
b=b-2;
ha=1;
c=0;
while ha:
luv3=100*(int(sq[0])*100+int(sq[1])*10+int(sq[2])-100*a*a-(20*a+b)*b)-c*(200*a+20*b+c);
c=c+1;
if luv3<0:
ha=0;
c=c-2;
print('root ',10*a+b,'.',c)
n=8
def hfactorial(n):
s=1;
for j in range(1,n+1):
s=s*j
return s
def hsin(x):
return x-x*x*x/6+x*x*x*x*x/120-x*x*x*x*x*x*x/5040;
def hcos(x):
return 1-x*x/2+1/24*x*x*x*x-x*x*x*x*x*x/720;
def htan(x):
return x+x*x*x/3+2/15*x*x*x*x*x+17/315*x*x*x*x*x*x*x+62/2035*x*x*x*x*x*x*x*x*x;
def h2cos(x):
s=0.0;
for j in range(n):
s=s+(-1)**j/hfactorial(2*j)*(x**(2*j))
return s
def h2sin(x):
s=0.0;
for j in range(n):
s=s+(-1)**j/hfactorial(2*j+1)*(x**(2*j+1))
return s
def h2sinh(x):
s=0.0;
for j in range(n):
s=s+1/hfactorial(2*j+1)*(x**(2*j+1))
return s
def h2atanh(x):
s=0.0;
for j in range(1,n):
s=s+1/(2*j-1)*(x**(2*j-1))
return s
def h2atan(x):
s=0.0;
for j in range(1,n):
s=s+(-1)**(j+1)/(2*j-1)*(x**(2*j-1))
return s
def h2ln1px(x):
s=0.0;
for j in range(1,n):
s=s+(-1)**(j+1)/j*(x**(j))
return s
def h2erf(x):
s=0.0;
for j in range(1,n):
s=s+2/np.sqrt(np.pi)*(-1)**j/(2*j+1)/hfactorial(j)*(x**(2*j+1))
return s
def h2exp(x):
s=0.0;
for j in range(1,n):
s=s+1/hfactorial(j)*(x**(j))
return s
def h2acot(x):
s=0.0;
for j in range(1,n):
s=s+(-1)**j/(2*j+1)*(x**(2*j+1))
return np.pi/2-s
def h2cosh(x):
s=0.0;
for j in range(1,n):
s=s+1/hfactorial(2*j)*(x**(2*j))
return s
print(h2cos(3.14/2),h2sin(0.1),h2sinh(0.1))