diff options
Diffstat (limited to 'python/code/1')
-rw-r--r-- | python/code/1/1.txt | 17 | ||||
-rw-r--r-- | python/code/1/2.txt | 52 | ||||
-rw-r--r-- | python/code/1/3.txt | 17 | ||||
-rw-r--r-- | python/code/1/4.py | 8 | ||||
-rw-r--r-- | python/code/1/6.py | 4 | ||||
-rw-r--r-- | python/code/1/7.py | 5 |
6 files changed, 103 insertions, 0 deletions
diff --git a/python/code/1/1.txt b/python/code/1/1.txt new file mode 100644 index 0000000..827a09a --- /dev/null +++ b/python/code/1/1.txt @@ -0,0 +1,17 @@ +>>> 2 + 3 +5 +>>> 1 + 2 * 3 - 4 +3 +>>> 12 * 5 / 3 * 2 +40.0 +>>> 5 / 8 +0.625 +>>> 23 // 7 +3 +>>> 17 % 5 - 1 +1 +>>> 3 * (4 + 5) + 5 +32 +>>> (2 + (7 + 2) / 3 - 4) / (-2 / 7 + (19 - 3 * 4) / 8) +1.696969696969697 + diff --git a/python/code/1/2.txt b/python/code/1/2.txt new file mode 100644 index 0000000..08c95b5 --- /dev/null +++ b/python/code/1/2.txt @@ -0,0 +1,52 @@ +>>> import math +>>> math.cos(math.pi / 3) +0.5000000000000001 +>>> math.sin(math.pi / 6) +0.49999999999999994 +>>> math.tan(math.pi / 4) +0.9999999999999999 +>>> math.pow(1.123, 0.123) +1.0143707323622344 +>>> math.exp(379) +3.959210944514706e+164 +>>> math.log(10, 2) +3.3219280948873626 +>>> math.hypot(3, 4) +5.0 +>>> math.hypot(3, 4, 5) +7.0710678118654755 +>>> math.degrees(math.pi / 4) +45.0 +>>> math.radians(90) / math.pi +0.5 +>>> [*(print(i, math.sqrt(i)) for i in range(1, 10))] +1 1.0 +2 1.4142135623730951 +3 1.7320508075688772 +4 2.0 +5 2.23606797749979 +6 2.449489742783178 +7 2.6457513110645907 +8 2.8284271247461903 +9 3.0 +[None, None, None, None, None, None, None, None, None]>>> math.modf(12.5) +(0.5, 12.0) +>>> math.gamma(6) +120.0 +>>> [math.floor(x) for x in [12.3, -12.3]] +[12, -13] +>>> [math.ceil(x) for x in [12.3, -12.3]] +[13, -12] +>>> [math.trunc(x) for x in [12.3, -12.3]] +[12, -12] +>>> math.cbrt(8), math.cbrt(10) +(2.0, 2.154434690031884) +>>> math.dist((1, 1), (2, 3)) +2.23606797749979 +>>> math.dist((1, 1), (5, 4)) +5.0 +>>> math.isqrt(23) +4 +>>> math.exp2(10) +1024.0 + diff --git a/python/code/1/3.txt b/python/code/1/3.txt new file mode 100644 index 0000000..90ebdbe --- /dev/null +++ b/python/code/1/3.txt @@ -0,0 +1,17 @@ +>>> a, b = 3 + 2j, 4 - 3j +>>> a + b, a - b, a * b, a / b +((7-1j), (-1+5j), (18-1j), (0.24+0.68j)) +>>> -a, -b +((-3-2j), (-4+3j)) +>>> (a + b) / (a - b) +(-0.4615384615384615-1.3076923076923077j) +>>> abs(a), abs(b) +(3.605551275463989, 5.0) +>>> a.imag, a.real +(2.0, 3.0) +>>> a.conjugate(), b.conjugate() +((3-2j), (4+3j)) +>>> from cmath import phase +>>> phase(a), phase(b) +(0.5880026035475675, -0.6435011087932844) + diff --git a/python/code/1/4.py b/python/code/1/4.py new file mode 100644 index 0000000..7579373 --- /dev/null +++ b/python/code/1/4.py @@ -0,0 +1,8 @@ +from math import gcd +a = int(input('Enter first number: ')) +b = int(input('Enter second number: ')) +print('Sum:', a + b) +print('Product:', a * b) +print('Difference:', a - b) +print('GCD:', gcd(a, b)) + diff --git a/python/code/1/6.py b/python/code/1/6.py new file mode 100644 index 0000000..e3a3cd0 --- /dev/null +++ b/python/code/1/6.py @@ -0,0 +1,4 @@ +a = float(input('Enter first number: ')) +b = float(input('Enter second number: ')) +print('Concatenation of integer parts:', ''.join(str(int(i)) for i in (a, b))) +print('Sum rounded to 2 decimal places:', round(a + b, 2)) diff --git a/python/code/1/7.py b/python/code/1/7.py new file mode 100644 index 0000000..37ecfa3 --- /dev/null +++ b/python/code/1/7.py @@ -0,0 +1,5 @@ +a = int(input('Enter first number: ')) +b = int(input('Enter second number: ')) +q, r = a // b, a % b +q1d, r1d = q % 10, r % 10 +print(f'The one’s place digits of quotient and remainder are {"" if q1d == r1d else "not"} equal.') |