1. Basic subtraction and take-rest operations
Print (5+10) Print (5-10) Print (5*10) Print (10/5) Print (5%3)2
2. Ask for n-Squared and square root
Print (5%3) Print (5**3) Print (125** (1/3)) Print (2**4) Print (16** ())4.0>>>
Use of the 3.math function library
Introduce the math library and see the value of pi
Import Math>>> math.pi3.141592653589793
(1) To find sine cosine function
>>> Math.sin (math.pi/2)1.0>>> math.cos (Math.pi/4)0.7071067811865476>> > Math.tan (Math.pi/4)0.9999999999999999>>>
(2) Rounding up and rounding down
>>> Math.floor (5.225)5>>> Math.ceil (5.225)6
Exercise: Apply a problem together
Apple 5 yuan a catty, grape 15 yuan a catty, sold a catty of apples 2.5 catty grapes, asked how much the total cost?
Solution:
# Apple spending ... # Grape Cost ... Print (5*1) Print (15*2.5) # Total Cost ... Print (5+37.5)42.5
Solution Two:
# Apple spending Print (apple_price*apple_weight) # Grape Cost Print (putao_price*putao_weight) # Total Cost Print (5+37.5)42.5>>>
>>> putao_toast = putao_price*putao_weight>>> apple_toast = apple_price*apple_weight Print(putao_toast + apple_toast)42.5
Solution three: Using the enhanced formatted string function format
" The total price of the grapes is {}, Apple's total price is {}, total cost { } " . Format (putao_toast,apple_toast,putao_toast+apple_toast) ' The total price of the grapes is 37.5, Apple's total price is 5, total cost 42.5 '
{} represents the parameter, there are several {}, pass several parameters, take parameters sequentially
Python as a calculator (mathematical usage)