python 作业,求助!
Writeaprogramthatrepeatedlypromptsauserforintegernumbersuntiltheuserenters'done'.Once...
Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter the numbers 4,5,6,7 and Match the desired output as shown below:
Invalid input
Maximum is 7
Minimum is 4
please build your program based on the sample code:
largest = None
smallest = None
while True:
num = raw_input("Enter a number: ")
if num == "done" : break
print num
print "Maximum", largest
用while 循环不断要求用户输入数字,直到用户输入done。然后打印出其中最大和最小的数字。 要求用try except检测用户输入的内容,如果输入的不是数字,则打印出invalid input。
用以下数字验证你的程序:4,5,6,7以及任意一个非数字字符
要求输出:
Invalid input
Maximum is 7
Minimum is 4
部分代码已经给出:
largest = None
smallest = None
while True:
num = raw_input("Enter a number: ")
if num == "done" : break
print num
print "Maximum", largest 展开
Invalid input
Maximum is 7
Minimum is 4
please build your program based on the sample code:
largest = None
smallest = None
while True:
num = raw_input("Enter a number: ")
if num == "done" : break
print num
print "Maximum", largest
用while 循环不断要求用户输入数字,直到用户输入done。然后打印出其中最大和最小的数字。 要求用try except检测用户输入的内容,如果输入的不是数字,则打印出invalid input。
用以下数字验证你的程序:4,5,6,7以及任意一个非数字字符
要求输出:
Invalid input
Maximum is 7
Minimum is 4
部分代码已经给出:
largest = None
smallest = None
while True:
num = raw_input("Enter a number: ")
if num == "done" : break
print num
print "Maximum", largest 展开
1个回答
展开全部
记得给采纳哦,不然我都回答得没劲了。
#!/usr/bin/env python
largest = None
smallest = None
LIST = []
while True:
num = raw_input("Enter a number: ")
if num == "done" : break
print num
try:
LIST.append(int(num))
except:
print "Invalid input"
largest = max(LIST)
smallest = min(LIST)
print "Maximum", largest
print "Minimum", smallest
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |