webnappad.com Python
Python request URL
file>Setting>Project:.> Project Interpreter> Type reuest> Install Package
Python Arithmetic Operators
[ Show Example ]
Operator Description Example
+ Addition Adds values on either side of the operator. a + b = 30
- Subtraction Subtracts right hand operand from left hand operand. a ? b = -10
* Multiplication Multiplies values on either side of the operator a * b = 200
/ Division Divides left hand operand by right hand operand b / a = 2
% Modulus Divides left hand operand by right hand operand and returns remainder b % a = 0
** Exponent Performs exponential (power) calculation on operators a**b =10 to the power 20
// Floor Division - The division of operands where the result is the quotient in which the digits
after the decimal point are removed. But if one of the operands is negative,
the result is floored, i.e., rounded away from zero (towards negative infinity) ?
ex) 9//2 = 4 and 9.0//2.0 = 4.0, -11//3 = -4, -11.0//3 = -4.0
https://www.tutorialspoint.com/python/python_basic_operators.htm
https://docs.python.org/2/howto/regex.html
https://regexcrossword.com/
/* Pythone define function */
-------------------------------------------
def month(s):
if 3 < s < 6:
r = "Spring"
elif s >=6 and s < 9:
r = "Summer"
elif 9 <= s < 12:
r = "Autumn"
else:
r = "Winter"
return r
while True:
n=int(input('Type Month==>'))
if n >= 1 and n <=12:
print(month(n))
break
--------------------------------------
result
Type Month==>12
Winter
--------------------------------------
/* Pythone Leap Year "À±³â" */
--------------------------------------
def year(n):
if n % 4 == 0:
if n % 100 != 0:
result = "Leap Year"
day = 29
else:
result = "NOT Leap Year"
day = 28
if n % 100 == 0 and n % 400 == 0:
result = "Leap Year"
day = 29
else:
result = "NOT Leap Year"
day = 28
return result,day
result=year(int(input("Type Year")))
print(result)
--------------------------------------
/* Pythone Array Sample */
--------------------------------------
n = 5
m=2
rclass = [[0] * m for i in range(n)]
for i in range(0,5,1):
rclass[i][0]=input("Type name")
rclass[i][1]=input("Type score")
name=[]
max=rclass[0][1]
for i in range(0,5,1):
if max< rclass[i][1]:
max = rclass[i][1]
max= rclass[i][0]
for i in range(0,5,1):
if max== rclass[i][1]:
name.append(rclass[i][0])
print(rclass)
print(name)
print(max)
#º¹»çÀÇ ÀÇ¹Ì (Copy in Python)
a=[10,20,30,40,50]
b=a
c=a.copy()
print('Original',a)
print('Copy address',b)
print('Copy value',c)
print('='*50)
a[0]=100
print('Original',a)
print('Copy address',b)
print('Copy value',c)
---------------------------------------------------
result
Original [10, 20, 30, 40, 50]
Copy address [10, 20, 30, 40, 50]
Copy value [10, 20, 30, 40, 50]
==================================================
Original [100, 20, 30, 40, 50]
Copy address [100, 20, 30, 40, 50]
Copy value [10, 20, 30, 40, 50]