Python Study Notes-numeric values

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.