简体   繁体   English

导出 python 中没有列表的最高和最低数字

[英]derive highest and lowest numbers without a list in python

I am tasked with returning high and low numbers from inputs.我的任务是从输入中返回高低数字。 I am restricted from using lists or importing functions.我被限制使用列表或导入函数。 this is what I have: The suggestion below failed.这就是我所拥有的:下面的建议失败了。 I suspect something is amiss in my code:我怀疑我的代码有问题:

I added this:我添加了这个:

在此处输入图像描述

My return was this:我的回报是这样的:

在此处输入图像描述

You must include the conditionals inside the loop and not outside.您必须在循环内部而不是外部包括条件。 This code will get you the oldest and youngest.此代码将为您提供最年长和最年轻的。

oldest = -1
youngest = 1000
for i in range(ppl):
     age = int(input("Age of Person: " + str(i+1) + ": "))
     total += age
     if age > oldest:
         oldest = age
     if age < youngest:
         youngest = age

print("Average age is:", total / ppl)
print("Oldest age is: ", oldest)
print("Youngest age is:", youngest)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM