在不同变量中分配 While 循环值的问题
Problem assigning values of a While loop in different variables
我正在为我的 phyton3 程序编写一个函数,它可以承受 7 个人的体重。
我不知道如何将这 7 个值分配给不同的变量,例如:
a = 0
while(a < 7):
p = int(input("Seu peso"))
a = a + 1
然后,他将不同的 "p" 值分配给不同的变量,例如 p1、p2、p3 ...
但以我"coding"的水平,根本做不到。
程序的一般用途是:
- 获取不同的权重
- 说说90kg以上的是哪些
- 计算数值的算术平均值。
这 3 个就是我需要不同变量的原因。
要得到7个人的体重,可以这样做:
weights = [] #This is a list
for i in range(7): #This is a for loop
w = int(input("Seu peso "))
weights.append(w)
说说90kg以上的重量是多少:
for w in weights:
if w > 90:
print(w, "Is greater than 90kg")
求均值:
mean = sum(weights)/len(weights)
print("Mean Weight:", mean)
我正在为我的 phyton3 程序编写一个函数,它可以承受 7 个人的体重。
我不知道如何将这 7 个值分配给不同的变量,例如:
a = 0
while(a < 7):
p = int(input("Seu peso"))
a = a + 1
然后,他将不同的 "p" 值分配给不同的变量,例如 p1、p2、p3 ...
但以我"coding"的水平,根本做不到。
程序的一般用途是:
- 获取不同的权重
- 说说90kg以上的是哪些
- 计算数值的算术平均值。
这 3 个就是我需要不同变量的原因。
要得到7个人的体重,可以这样做:
weights = [] #This is a list
for i in range(7): #This is a for loop
w = int(input("Seu peso "))
weights.append(w)
说说90kg以上的重量是多少:
for w in weights:
if w > 90:
print(w, "Is greater than 90kg")
求均值:
mean = sum(weights)/len(weights)
print("Mean Weight:", mean)