Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import numpy as np def menu(): print(MENU) print(__________________________) print(1) Create a 3-by-3 Array) print(2) Display cube Values for elements in array) print(3) Add 7 to

import numpy as np def menu(): print("MENU") print("__________________________") print("1) Create a 3-by-3 Array") print("2) Display cube Values for elements in array") print("3) Add 7 to every element and display result") print("4) Multiply elements by 6 and display result") print("5) Exit") menu()

choice = int(input("Please select a menu option between 1 and 5: ")) evens = np.array while choice != 0: if choice == 1: evens = np.arange(1,10).reshape(3,3) print(str(evens*2).replace(' [', '').replace('[', '').replace(']', '')) elif choice == 2: cubed = (evens*2) **3 print(str(cubed).replace(' [', '').replace('[', '').replace(']', '')) elif choice == 3: addition = (evens*2) + 7 print(str(addition).replace(' [', '').replace('[', '').replace(']', ''))

elif choice == 4: multiply = (evens*2) * 6 print(str(multiply).replace(' [', '').replace('[', '').replace(']', '')) elif choice == 5: print("Exiting program") break else: print("invalid option") print() menu() choice = int(input("Please select a menu option between 1 and 5: "))

I have this program written so far. It does what I want it to do, but I can not figure out how to have the if statements 2-4 verify if the array was created in choice 1. It runs well if I create the array in choice 1 first then proceed with the options. If I go straight to option 2 it gives me an error. I need the program to verify if the array in option 1 was created first and if not state that the array has not been created and then pull the menu open once again to make another choice. This is in python

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

Define Management by exception

Answered: 1 week ago

Question

Explain the importance of staffing in business organisations

Answered: 1 week ago

Question

What are the types of forms of communication ?

Answered: 1 week ago

Question

Explain the process of MBO

Answered: 1 week ago