-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05mathinpython.py
More file actions
89 lines (71 loc) · 1.4 KB
/
05mathinpython.py
File metadata and controls
89 lines (71 loc) · 1.4 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
77
78
79
80
81
82
83
84
85
86
87
88
89
# kita akan belajar bagaimana melakukan matematika di python
# yg akan dibahas berupa: arithmetic, math function, dan exercise
# friends = 2
# friends = friends + 1
# this code does the same thing the above code do
# friends += 1
# substraction
# friends = friends - 2
# friends -= 2
# multiplication
# friends = friends * 2
# friends *= 2
# division
# friends = friends / 2
# friends /= 2
# exponent
# friends = friends ** 2
# friends **= 2
# modulo
# remainder = 5
# remainder = friends % 3
# remainder %= 4
# print(remainder)
# math function
z = 5
# membulatkan
# x = 3.14
# result = round(x)
# print(result)
# output: 3
# absolute number
# y = -4
# result = abs(y)
# print(result)
# output: 4
# power function
# result = pow(4, 3)
# print(result)
# output: 64
# maximum value
# x = 3.14
# y = 4
# z = 5
# maks = max(x, y, z)
# mim = min(x, y, z)
# print(f"Nilai maksimum: {maks}")
# print(f"Nilai minimum: {mim}")
# output:
# Nilai maksimum: 5
# Nilai minimum: 3.14
# math module:
import math
# print(math.pi)
# output: 3.141592653589793
# print(math.e)
# output: 2.718281828459045
# squareroot
# x = 9
# result = math.sqrt(x)
# print(f"Square root of x is: {result}")
# output: Square root of x is: 3.0
# ceiling funciton, rounded floating number up
# x = 1.1
# result = math.ceil(x)
# print(result)
# output: 2
# floor funciton, rounded floating number down
x = 1.1
result = math.floor(x)
print(result)
# output: 1