python中 怎么用while loop算数量 5
YourPythonprogramwilldothefollowing:CreateanemptylistUseaforlooptoasktheuserfor10numb...
Your Python program will do the following:
Create an empty list
Use a for loop to ask the user for 10 numbers. Add each number to your list using the append method.
Use another for loop to print the list in reverse order, one per line
Use a while loop to count how many positive numbers are in the list
Here is one example of how the program should look when it runs (user input is in red):
Enter a number: 3
Enter a number: 2
Enter a number: -4
Enter a number: 10
Enter a number: -8
Enter a number: 17
Enter a number: -20
Enter a number: 30
Enter a number: -5
Enter a number: -2
Reversed list:
-2
-5
30
-20
17
-8
10
-4
2
3
Positive count: 5 展开
Create an empty list
Use a for loop to ask the user for 10 numbers. Add each number to your list using the append method.
Use another for loop to print the list in reverse order, one per line
Use a while loop to count how many positive numbers are in the list
Here is one example of how the program should look when it runs (user input is in red):
Enter a number: 3
Enter a number: 2
Enter a number: -4
Enter a number: 10
Enter a number: -8
Enter a number: 17
Enter a number: -20
Enter a number: 30
Enter a number: -5
Enter a number: -2
Reversed list:
-2
-5
30
-20
17
-8
10
-4
2
3
Positive count: 5 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询