Notes on python personally used things (input, trigonometric functions, logarithms)

I will write functions that I often use (personally) in university reports and AtCoder.

0. Those used for input in competition pros

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())

1. 1. Trigonometric function

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

2. Logarithmic function

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

Notes on python personally used things (input, trigonometric functions, logarithms)
[Golang] Notes on frequently used functions
Frequently used (personally) notes on the tar command
Notes on SciPy.linalg functions
[Python] Notes on data analysis
Notes on installing Python on Mac
Notes on installing Python on CentOS
Notes on Python and dictionary types
Tips on Python file input / output
Notes on using MeCab from Python
Notes on installing Python using PyEnv
Notes for Python file input / output
Notes on using rstrip with python.
Notes on accessing dashDB from python
Notes for using OpenCV on Windows10 Python 3.8.3.
Notes on PyQ machine learning python grammar
Notes on nfc.ContactlessFrontend () for nfcpy in python
Notes on standard input / output of Go
Notes on doing Japanese OCR with Python
Notes on building Python and pyenv on Mac
Notes on using code formatter in Python