Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q2: Write in Python programming: a) Write a script that generate a list of 10 lists, each of which contains 10 random number between 0

Q2: Write in Python programming:

a) Write a script that generate a list of 10 lists, each of which contains 10 random number between 0 and 100. Print the list with 10 numbers per line.

Output example:

60 33 9 46 76 83 84 90 11 23

65 74 42 87 52 10 98 57 71 19

99 25 71 15 96 39 15 71 16 16

93 91 29 83 79 62 23 49 94 29

70 2 69 80 38 33 28 86 56 94

60 61 98 34 20 88 69 11 7 36

15 0 63 97 53 80 80 89 4 44

80 29 38 54 24 97 43 56 47 58

64 100 45 71 17 41 4 52 100 17

  1. 8 98 98 51 79 53 17 48 57

b) Create a tuple that contains course codes:

('2400', '3560', '3140', '3040','4100', '4700', '4500')

Do the following:

1- Convert the tuple to a tuple that changes the course abbreviations to full course names (with the COMP-):

('COMP-2400', 'COMP-3560', 'COMP-3140', 'COMP-3040', 'COMP-4100', 'COMP-4700', 'COMP-4500').

Print it.

2- Let Python randomly select a course and print the course.

3- Finally, make a new tuple with the randomly selected course replaced by the word LuckyCourse in the tuple. Print the new tuple.

**********

Running example:

The original tuple of abbreviation is: ('2400', '3560', '3140', '3040', '4100', '4700', '4500')

The tuple of full-name is:

('COMP-2400', 'COMP-3560', 'COMP-3140', 'COMP-3040', 'COMP-4100', 'COMP-4700', 'COMP-4500')

Your lucky course is: COMP-4700

The new tuple is:

('COMP-2400', 'COMP-3560', 'COMP-3140', 'COMP-3040', 'COMP-4100', 'luckyCourse', 'COMP-4500')

  1. Write a script that creates a dictionary of name-age pair. Add some entries to your dictionary. Add a menu to support ADD, REMOVE, SERACH, AGE INCREASE, PRINToperations. The Age Increase option increases the age by 1 for all the entries in the dictionary.

Test the four operations. Show testing screenshot.

Running Example:

{'John': 34, 'Amy': 59, 'Bob': 26, 'Gorge': 60}

Operations

1. Search

2. Add

3. Remove

4. Age Increase

5. Print Dictionary

6. Exit

Select 1-5: 1

Enter name to search: Bob

Bob 26

Operations

1. Search

2. Add

3. Remove

4. Age Increase

5. Print Dictionary

6. Exit

Select 1-5: 2

Enter name: Allen

Enter age: 45

{'John': 34, 'Amy': 59, 'Bob': 26, 'Gorge': 60, 'Allen': 45}

Operations

1. Search

2. Add

3. Remove

4. Age Increase

5. Print Dictionary

6. Exit

Select 1-5: 3

Enter name: Amy

{'John': 34, 'Bob': 26, 'Gorge': 60, 'Allen': 45}

Operations

1. Search

2. Add

3. Remove

4. Age Increase

5. Print Dictionary

6. Exit

Select 1-5: 4

{'John': 35, 'Bob': 26, 'Gorge': 60, 'Allen': 45}

Operations

1. Search

2. Add

3. Remove

4. Age Increase

5. Print Dictionary

6. Exit

Select 1-5: 5

John 35

Bob 27

Gorge 61

Allen 46

Operations

1. Search

2. Add

3. Remove

4. Age Increase

5. Print Dictionary

6. Exit

Select 1-5: 6

Goodbye!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions