Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started