Obtain the precision of different circumference rates
Import mathfor precision in range (10): Print round (math. Pi, precision)
Int, round, math. Floor differences
- The int () function removes the fractional part and returns an integer.
- Function floor () to obtain the floating point number closest to the original number but smaller than the original number.
- The function round () is rounded to the nearest integer to return a floating point number.
Import math
For N in (. 2,. 7, 1.2, 1.7,-. 2,-. 7,-1.2,-1.7 ):
Print "int (%. 1f) \ t % +. 1f" % (n, INT (n ))
Print "floor (%. Lf) \ t % +. Lf" % (n, math. Floor (n ))
Print "round (%. Lf) \ t % +. Lf" % (n, round (n ))
Print '-' * 20
Enter a test score and output his score (A-E) based on the following criteria)
- A: 90 ~ 100
- B: 80 ~ 89
- C: 70 ~ 79
- D: 60 ~ 69
- E:
# Coding = 'utf-8' n = raw_input ("enter a 0 ~ 100 of the score ") n = int (n) If 90 enter a year to determine whether it is a leap year
year = raw_input ('Enter the year to be checked ') year = int (year) if (Year % 4 = 0 and Year % 100! = 0) or (Year % 400 = 0): Print year, 'is a leap year' else: Print year, 'Not a leap year' obtains an amount less than $1, and then calculates the minimum number of coins that can be converted. coins can be 1 cent, 5 cents, 10 cents, 25 cents, and 4 types. $1 equals 100 cents. for example, the Conversion Result of $0.76 should be 3x25 cents and 1x1 cent. similar to 76 pieces of 1 cent, 2 pieces of 25 cents + 2 pieces of 10 cents + 1 piece of 5 cents + 1 piece of 1 cent results are not required!
# Coding = 'utf-8' n = raw_input (" enter an amount less than $1 ") n = int (float (n) * 100) ret = ''for I in (25, 10, 5, 1): If I JS is an array join string, python is a string join array