In [2]:
def computer_square(end):
total_end = 1
for i in range(end):
total_end = total_end * (i+1)
return total_end
m = int(input('请输入第一个整数,以回车结束。'))
n = int(input('请输入第二个整数,以回车结束。'))
k = int(input('请输入第三个整数,以回车结束。'))
print('最终的和是', computer_square(m) + computer_square(n) + computer_square(k))
In [23]:
def computer_total(end):
i = 1
total_end = 1
for i in range(1,end+!):
total_end = total_end + -1 ** i *(1/(2*i)+1)
i = i + 1
return total_end
print('最终的和是', (computer_total(1000) + computer_total(100000))*4)
In [26]:
def computer_total(x, y, z):
total = 0
for a in range(x, y+1, z):
total = total + a
return total
m = int(input('请输入起始数字'))
n = int(input('请输入终止数字'))
k = int(input('请输入间隔大小'))
print('和为', computer_total(m, n, k))
In [ ]:
def computer(x, y, t):
total = 0
i = 0
while i < t:
import random
number = random.randint(x, y)
total = total + number
i = i + 1
aver = total/t
import math
squareroot = math.sqrt(aver)
print(squareroot)
n = int(input('请输入随机数个数n '))
m = int(input('请输入整数下限m '))
k = int(input('请输入整数上限k '))
computer(m, k, n)
In [3]:
def printlist(numbers):
total = 0
for number in numbers:
total = total + number
return total
numberlist = [1,2,3,4,5,6,7]
print(numberlist)
printlist(numberlist)
Out[3]:
In [8]:
def choosemin(numbers):
number_min = numbers[0]
for number in numbers:
if number < number_min:
number_min = number
return(number_min)
numberlist = [7,1,2,3,5,8,4]
print(numberlist)
choosemin(numberlist)
Out[8]:
老师,题,没太读懂【捂脸 那个被判断的元素,是手动输入的? 可以讲一下吗,爱您~❤️
In [12]:
import math
def compute_cos(vector1,vector2):
total1 = 0
total2 = 0
for vector in vector1:
total1 = total1 + vector**2
a = math.sqrt(total1)
for vector in vector2:
total2 = total2 + vector**2
b = math.sqrt(total2)
fenzi = vector1[0]*vector2[0] + vector1[1]*vector2[1]
cos = fenzi/a*b
return cos
vector1list= [1,1]
vector2list= [0,1]
print(vector1list,vector2list)
compute_cos(vector1list,vector2list)
Out[12]:
In [19]:
total = 0
for a in range(5, 101):
for b in range(5, 101-a):
for c in range(5, 101-a-b):
if a + b + c == 100:
total = total + 1
print(total)
In [21]:
total1 = 0
total2 = 0
for a in range(5, 101):
for b in range(5, 101-a):
c = 100 - a - b
if a + b + c == 100:
total1 = total1 + 1
total2 = total2 + 1
print(total2)