【问题描述】有学生70人组织春游,要租用大巴,每辆大巴可承载30人,至少要多少辆大巴可装载全部学生?,请问每辆车要装载多少学生才能让每辆车的人数较为平均的分布,请输出每辆车的所载人数。
【解题思路】先求得最少须要多少辆大巴,获得大巴数目后须要尽可能将学平生均分到全部大巴上,因此能够用整除运算来求得每辆车平均装载人数。python
student = 70; seat = 30 num = student // seat r = student % seat if r != 0: #若是在学生坐满大巴后还有一些学生 num = num + 1 ave = student // num if r == 0: #若是学生刚好能将大巴都坐满 print(num,"buses. Each has ",ave," students.") else: lastbus = student-(num-1)*ave print(num,"buses. One bus has ",lastbus," students.") print("Each of other buses has ",ave," students.")
【问题描述】已知二维线性方程组以下,其中, a0 、a1 、b0 、b1 、c0和c1为已知,求未知量x和y的值。
web
#方程组系数 a0, b0 , c0 = 3, 1 ,4 a1, b1 , c1 = 0, -2, -1 #等式1两边同时扩大a1倍 a2, b2 , c2 = a0 * a1, b0 * a1, c0 * a1 #等式2两边同时扩大a0倍 a3, b3 , c3 = a1 * a0, b1 * a0, c1 * a0 #等式1减等式2 a , b, c = a2 -a3, b2 - b3, c2- c3 if ((b == 0) and (c == 0)): print("Infinite Solution!") elif (b == 0): print("No Solution!") elif (a0 == 0): y = c0 / b0 x = (c1 - b1 * y) / a1 print("x =%.2f , y = %.2f" % (x, y)) elif (a1 == 0): y = c1 / b1 x = (c0 - b0 *y) / a0 print("x =%.2f , y = %.2f" % (x, y)) else: y = c / b x = (c0 - b0 * y) / a0 print("x = %.2f, y = %.2f" % (x, y))