The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
I don't think I am understanding python and I keep getting an error! I would like some help with this!
_______________________________________________________________________
Â
CIS115         Introduction to Programming and Logic                    Â
_______________________________________________________________________
Â
Â
LAB 11Â Â Â Â Â Â LISTS AND TYPLES [PART 1]
Â
In this lab assignment, students will learn:
- How to create lists
- How to write code to combine lists
- How to write code to find largest and smallest elements in a list
- How to write code to remove elements from a list
Â
In this lab assignment, students will demonstrate the abilities to:
- Create lists
- Write code to combine lists
- Write code to find largest and smallest elements in a list
- Write code to remove elements from a list
Â
Write a Python program for each of the problems in this lab. The following is an example.
Â
Write a program to check whether a product code entered by the user is in the product list.
Â
Python program:
Â
def main():
prod_nums = ['V475', 'F987', 'Q143', 'R688']
search = input('Enter a product number: ')
if search in prod_nums:
print(search, 'was found in the list')
else:
print(search, 'was not found in the list')
Â
main()
Â
Please use PyCharm to type and test your programs. Submit the Python files to Blackboard for credit. In this lab, you should submit 2 Python files, one for each problem.
Â
Â
An instructor teaches two classes this semester. Recently he gave the same test to both classes. Write a program to analyze the test scores.
Â
(a) Enter the scores of students in class 1. Every time after a score is entered, ask whether the user wants to enter another score. Store the scores in a list.
(b) Enter the scores of students in class 2. Every time after a score is entered, ask whether the user wants to enter another score. Store the scores in a list.
(c)Â Display the number of scores in class 1 and all the scores in class 1.
(d) Display the number of scores in class 2 and all the scores in class 2.
(e) Combine the two score lists. Display the combined list.
(f)Â Â Display the highest score in the combined list.
(g) Display the lowest score in the combined list.
(h) Sort the scores in the combined list in ascending order (i.e. from smallest to largest). Display the sorted list.
(i)  Sort the scores in the combined list in descending order (i.e. from largest to smallest). Display the sorted list.
Â
The following is an example.
Â
Enter test scores of class 1.
Enter a score: 56
Add another score? [y/n] y
Â
Enter a score: 78
Add another score? [y/n] y
Â
Enter a score: 89
Add another score? [y/n] n
Â
Enter test scores of class 2.
Enter a score: 99
Add another score? [y/n] y
Â
Enter a score: 78
Add another score? [y/n] n
Â
There are 3 students in class 1.
Scores in class 0001:
[56.0, 78.0, 89.0]
There are 2 students in class 2.
Scores in class 0002:
[99.0, 78.0]
There are 5 students in class 1 and class 2 combined.
Scores in combined list:
[56.0, 78.0, 89.0, 99.0, 78.0]
The highest score in the combined list is 99.0
The lowest score in the combined list is 56.0
Scores in the combined list sorted in ascending order:
[56.0, 78.0, 78.0, 89.0, 99.0]
Scores in the combined list sorted in descending order:
[99.0, 89.0, 78.0, 78.0, 56.0]
Â
Save your Python program in a file named Lab11P1.py. Submit the file to Blackboard for credit.
Â
Â
Write a program to do the following:
Â
(a) Generate 10 random integers in the range of 1 through 4. Store them in a list named list1. Display list1.
(b) Create a new list named list2.Copy the last 5 elements oflist1 there. Display list2.
(c) Remove all occurrences of 2 from list2. Display the list. There should be no 2s in there anymore.
Â
The following is an example.
Â
List 1:
[4, 1, 1, 3, 3, 3, 2, 4, 2, 4]
List 2:
[3, 2, 4, 2, 4]
List 2 with all 2s removed:
[3, 4, 4]
Â
Save your Python program in a file named Lab11P2.py. Submit the file to Blackboard for credit.
Â
Â
Storing scores in lists and displaying lists [10 points]
Displaying number of scores in each list [10 points]
Combining lists[10 points]
Finding highest score [10 points]
Finding lowest score [10 points]
Sorting scores in ascending order [10 points]
Sorting scores in descending order [10 points]
Â
Creating list of random numbers [10 points]
List slicing [10 points]
Removing all occurrences of 2 [10 points]
Â
Â
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly