习题1 求方程 ax^2+bx+c=0 的根
import math
def root():
a = int(input('Enter a: '))
b = int(input('Enter b: '))
c = int(input('Enter c: '))
judge = b**2-4*a*c
r1 = (-1*b+(math.sqrt(judge)))/2*a
r2 = (-1*b-(math.sqrt(judge)))/2*a
if judge > 0:
print('The roots are %s and %s'%(r1,r2))
elif judge == 0:
print('The roots is %s'%r1)
else:
print('The equation has no real roots')
root()
(base) C:\Users\Administrator>F:/install/Anaconda/python.exe d:/VScode/Untitled-Tue2.py
Enter a: 3
Enter b: 4
Enter c: 1
The roots are -3.0 and -9.0
习题2
import random
num1 = random.randint(1,100)
num2 = random.randint(1,100)
a = int(input('num1 = '))
b = int(input('num2 = '))
sum1 = int(input('请输入两个整数的和:'))
print(a + b)
def sum():
sum = a+b
if sum1 == sum:
print('结果为真')
else:
print('结果为假')
sum()
(base) C:\Users\Administrator>F:/install/Anaconda/python.exe d:/VScode/Untitled-Tue2.py
num1 = 6
num2 =