Starting from 0 to learn python,0 Foundation small white

Source: Internet
Author: User
Tags arithmetic square root cmath

Python3 First day of study

function calculation

#用户输入数字

NUM1 = input (' Enter the number you want to calculate here: ')

num2 = input (' Enter a second number: ')

num3 = input (' can also input three numbers OH: ')

#计算公式

sum = float (NUM1) +float (num2) *float (num3)

#输出结果

Print (' number {0} ' and ' number ' {1} ' added multiplied by the number {2} result is: {3} '. Format (num1,num2,num3,sum))

Personal understanding

The meaning of input in English

NUM1 equivalent to defining the input function

Float is a value that is defined as a floating number

Sum is the result of a function operation

Print let the machine printing meaning

format, formatted string, {0} ...

Simplifying Code Bits

Print (' Sum of two bundles:%1.f '% (float (input (' Enter first number: ') ') +float (Input (' Enter second number: '))))

Mean

Output operation module result is%

The sum of two numbers of Chinese characters is:

%1.f a digit after the decimal point, rounded later

Operation module Within ()

To define the input (enter the first number: after) The value is a floating number

+ On the second floating number operation

Python operators

Except-X divided by y

Modulo-returns the remainder of division

valign= "to P ">

+

Plus-two objects added

A + b output results

-

minus-get negative numbers or one number minus another"

A-B output -11

*

Multiply by two numbers or return a repeated number of times The string

A * b output of the result of the

/

b/a Output 2.1

%

B% A output 1

**< /p>

Power-returns the y power of x

A**b is 10 of 21 parties

//

Divide-return the integer portion of the quotient

9//2 output result 4, 9.0//2.0 output 4.0< /p>

Extrapolate

Two ways of writing mathematical operations

First define NUM and write the sum formula to the final output format, print (' Result {0}{1} '. Format (String, String))

Simplified code for print (' Result '% (string arithmetic process))

Python3 Study the next day

Python3 instances

The square root, also called two square roots, is expressed as (√ ̄), such as: The Mathematical language is: √ ̄16=4. The language is described as: 16=4 under the square root.

The following example enters a number by the user and calculates the square root of the number:

‘‘‘

Print (' The square root of this number is:%.9f '% (float (input (' Enter a number: ')) * * 0.5))

Knowledge Point One: the reciprocal of the square root to power

The arithmetic formula is num_sqrt=num**0.5

Extension code

#定义输入数字为字符串

num= Float (input ' Enter first number: ')

#告诉运算公式

NUM_SQRT = num * * 0.5

#输出结果

Print (' {0:%.1f} ' square root is {1:%.1f} '. Format (NUM,NUM_SQRT))

#缺点没定义小数数量

#定义输入数字为字符串

num = float (input (' Enter the number to be computed: '))

#告诉运算公式

NUM_SQRT = num * * 0.5

#输出结果

Print (' The square root of the digital%.3f is%.4f '% (num, num_sqrt))

#缺点没定义小数数量

#简化公式为

Print (' The square root of the number is%.4f '% (float (input (' Enter the number to be computed: ')) * * 0.5))

# calculates real and complex square roots

# import Complex Math module

Import Cmath

num = Int (input ("Please enter a number:"))

NUM_SQRT = cmath.sqrt (num)

Print (the square root of ' {0} is {1:0.3f}+{2:0.3f}j '). Format (num, num_sqrt.real,num_sqrt.imag))

Import importing module meaning load

CAMTH Module Library's complex operation module

Starting from 0 to learn python,0 Foundation small white

Related Article

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.