# Untitled

a guest
Dec 20th, 2015
281
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import sys
2.
3.
4. def method1(a, b):
5.     s = 0
6.     aa = list()
7.     bb = list()
8.     ss = list()
9.     while True:
10.         ss.append(s)
11.         aa.append(a)
12.         bb.append(b)
13.         if a == 0:
14.             break
15.         s = s if a % 2 == 0 else s + b
16.         a = a // 2
17.         b = b * 2
18.
19.     len_a = len(str(aa[0])) + 1
20.     len_b = len(str(bb[-1])) + 1
21.     pattern = '{{:>{}}} \u2A2F {{:<{}}} \u2192  {{}}'.format(len_a, len_b)
22.
23.     for i in range(len(aa)):
24.         if i == 0 or ss[i] != ss[i-1]:
25.             print(pattern.format(aa[i], bb[i], ss[i]))
26.         else:
27.             print(pattern.format(aa[i], bb[i], ''))
28.
29.
30. def method2(a, b):
31.     s = a * b
32.     pattern = '{{:>{}}}'.format(len(str(s)))
33.     bb = list(reversed(str(b)))
34.     zz = list()
35.     for i, _b in enumerate(bb):
36.         zz.append('{}{}'.format(a * int(_b), ' '*i))
37.
38.     print(pattern.format(a))
39.     print(pattern.format(b))
40.     print('='*len(str(s)))
41.     for z in zz:
42.         print(pattern.format(z))
43.
44.     print('='*len(str(s)))
45.     print(pattern.format(s))
46.
47.
48. def main():
49.     if len(sys.argv) < 3:
50.         print("blablabla argv")
51.         exit(1)
52.
53.     try:
54.         a = int(sys.argv[1])
55.         b = int(sys.argv[2])
56.     except ValueError:
57.         print("blablabla value")
58.         exit(1)
59.     else:
60.         method1(a, b)
61.         print()
62.         print('#'*80)
63.         print()
64.         method2(a, b)
65.
66. if __name__ == "__main__":
67.     main()
RAW Paste Data