【坚持】Selenium+Python学习之从读懂代码开始 DAY2

2018/05/10

[来源:菜鸟教程](http://www.runoob.com/python3/python3-examples.html

#No.1
# 二次方程式 ax**2 + bx + c = 0
# a、b、c 用户提供
 
# 导入 cmath(复杂数学运算) 模块
'''
cmath.sqrt(x)
Return the square root of x. 
'''
import cmath

a = float(input('please input a:'))
b = float(input('please input b:'))
c = float(input('please input c:'))

d = (b**2) - (4*a*c)

sol1 = (-b-cmath.sqrt(d))/(2*a)
sol2 = (-b+cmath.sqrt(d))/(2*a)

print('result is {0} and {1}'.format(sol1,sol2))
result:

d:\fly\HTML
λ python test.py
please input a:4
please input b:5
please input c:6
result is (-0.625-1.0532687216470449j) and (-0.625+1.0532687216470449j)
#No.2
'''
random.randint(a, b)
Return a random integer N such that a <= N <= b. Alias for randrange(a, b+1).
'''

import random
print(random.randint(0 , 9))
print(random.randrange(0 , 9))
result:

d:\fly\HTML
λ python test.py
0
3
#No.3
num = float(input('please input a num:'))
if num > 0:
    print('positive number')
elif num == 0:
    print('zero')
else:
    print('negative number')

or

num = float(input('please input a num:'))
if num >=0:
    if num == 0:
        print('zero')
    else:
        print('positive number')
else:
    print('negative number')
result:
d:\fly\HTML
λ python test.py
please input a num:8
positive number

d:\fly\HTML
λ python test.py
please input a num:0
zero

d:\fly\HTML
λ python test.py
please input a num:-9
negative number

猜你喜欢

转载自www.cnblogs.com/flyin9/p/9017859.html