I will write functions that I often use (personally) in university reports and AtCoder.
One integer, decimal, and string are received as XX (input ()). XX is a type.
N = int(input)#integer
f = float(input())#a few
S = str(input())#String
If you want to receive multiple inputs in one line, use map (〇〇, input (). Split ()). If you forget split (), you will eat RE, so be careful. (Self-discipline)
a,b,c = map(int, input().split())
s,t,u = map(str, input().split())
When receiving the list at the end, use list (map (○○, input (). Split ())).
A = list(map(int, input().split()))
S = liat(map(int, input().split())
Conversion of sin, cos, tan, frequency method, radian method The inside of () seems to be basically handled by the radian method. math.pi is pi.
import math
x = math.pi/3
s = math.sin(x)
c = math.cos(x)
t = math.tan(x)
#s = 0.8660254
#c = 0.5000000
#t = 1.73205
If you want to handle the arc degree method and the degree method, use math.radians and math.degrees.
import math
rad = math.radians(60)
deg = math.degrees(math.pi)
c = math.cos(math.radians(60))
#rad = 1.04710
#deg = 59.9999999
#c = 0.500000
You can use math.log (antilogarithm, base), but if you do not specify the base, the base is calculated by e or math. If the bases are 2 and 10, it seems that you can also write as below. Napier numbers can be used in math.e.
import.math
l_e = math.log(1)#The bottom is e(Napier number)
l_2 = math.log2(4)#The bottom is 2
l_10 = math.log10(1000)#The bottom is 10
l_3 = math.log(81,3)
#l_e = 0.0
#l_2 = 2.0
#l_10 = 3.0
#l_3 = 4.0
Recommended Posts