Question

In: Computer Science

(Python) How would I add this input into my code? "Enter Y for Yes or N...

(Python) How would I add this input into my code? "Enter Y for Yes or N for No:" as a loop.

def getMat():
mat = np.zeros((3, 3))
print("Enter your first 3 by 3 matrix:")
for row in range(3):
li = [int(x) for x in input().split()]
mat[row,0] = li[0]
mat[row,1] = li[1]
mat[row,2] = li[2]
print("Your first 3 by 3 matrix is :")
for i in range(3):
for k in range(3):
print(str(int(mat[i][k]))+" ",end="")
print()
return mat

def checkEntry(inputValue):
try:
float(inputValue)
except ValueError:
return False
return True

print('Enter first matrix: ')
mat1 = getMat()

print('Enter second matrix: ')
mat2 = getMat()

print('Select a Matrix Operation from the list below:')
print('a. Addition')
choice = str(input())

while choice != 'e':
if choice == 'a':
print('You selected Addition. The results are: ')
res = mat1 + mat2

Solutions

Expert Solution

import numpy as np


def getMat():
    mat = np.zeros((3, 3))
    print("Enter your first 3 by 3 matrix:")
    for row in range(3):
        li = [int(x) for x in input().split()]
        mat[row, 0] = li[0]
        mat[row, 1] = li[1]
        mat[row, 2] = li[2]
    print("Your first 3 by 3 matrix is :")
    for i in range(3):
        for k in range(3):
            print(str(int(mat[i][k])) + " ", end="")
        print()
    return mat


def checkEntry(inputValue):
    try:
        float(inputValue)
    except ValueError:
        return False
    return True


while True:
    print('Enter first matrix: ')
    mat1 = getMat()

    print('Enter second matrix: ')
    mat2 = getMat()

    print('Select a Matrix Operation from the list below:')
    print('a. Addition')
    choice = str(input())

    while choice != 'e':
        if choice == 'a':
            print('You selected Addition. The results are: ')
            res = mat1 + mat2
    choice = input('Enter Y for Yes or N for No:')
    if choice == 'N' or choice == 'n':
        break

Related Solutions

Python I want to name my hero and my alien in my code how do I...
Python I want to name my hero and my alien in my code how do I do that: Keep in mind I don't want to change my code except to give the hero and alien a name import random class Hero:     def __init__(self,ammo,health):         self.ammo=ammo         self.health=health     def blast(self):         print("The Hero blasts an Alien!")         if self.ammo>0:             self.ammo-=1             return True         else:             print("Oh no! Hero is out of ammo.")             return False     def...
How would I add an automatic please fill out this info to my complete code. Something...
How would I add an automatic please fill out this info to my complete code. Something similar to this code. <!doctype html> <html> <head> <meta charset="UTF-8"> <title>Untitled Document</title> <script>    function phonenumber(inputtxt){           var phoneno = (\(\d{3}\)|\d{3})[-\s]\d{3}-\d{4};       if(inputtxt.value.match(phoneno)){        document.getElementById("yourEntry").innerHTML = document.getElementById("myphone").value;    }    //if(!inputtxt.value.match(phoneno)){        // alert("Does not Work!")        //}    } </script> </head> <body> <form name="form1" action="#"> <input type="text" name="myphone" id="myphone" value="" pattern= "(\(\d{3}\)|\d{3})[-\s]\d{3}-\d{4}" placeholder="(555) 555-1212" required /> <input...
Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
HOW DO I ADD ON TO THIS CODE SO THAT IT DISPLAYS ALL THE VALUES INPUT...
HOW DO I ADD ON TO THIS CODE SO THAT IT DISPLAYS ALL THE VALUES INPUT BY THE USER AS SPECIFIED IN THEH FIRST PART OF THE QUESTION? Ask the user to enter a number and display the number, followed by ***, followed by the number squared, followed by &&&, and followed by the number cubed. Allow the user to enter as many numbers as he/she wishes. So, use a reasonable sentinel value to end the loop (for example, -999)....
In Python I have a code: here's my problem, and below it is my code. Below...
In Python I have a code: here's my problem, and below it is my code. Below that is the error I received. Please assist. Complete the swapCaps() function to change all lowercase letters in string to uppercase letters and all uppercase letters to lowercase letters. Anything else remains the same. Examples: swapCaps( 'Hope you are all enjoying October' ) returns 'hOPE YOU ARE ALL ENJOYING oCTOBER' swapCaps( 'i hope my caps lock does not get stuck on' ) returns 'I...
How do I add the information below to my current code that I have also posted...
How do I add the information below to my current code that I have also posted below. <!DOCTYPE html> <html> <!-- The author of this code is: Ikeem Mays --> <body> <header> <h1> My Grocery Site </h1> </header> <article> This is web content about a grocery store that might be in any town. The store stocks fresh produce, as well as essential grocery items. Below are category lists of products you can find in the grocery store. </article> <div class...
I need to add this checkpoint to an existing code that i have in python Checkpoint...
I need to add this checkpoint to an existing code that i have in python Checkpoint 1: Once you have created and tested the Bank Account Class create subclasses to the BankAccount class. There should be two subclasses, CheckingAccount and SavingsAccount. You should add interest_rate to the parent BankAccount class. To the CheckingAccount add variables called per_check_fee default to false and allow_overdraft default to True. To SavingsAccount add the variable transactions_per_month, default it to 5. Create instances of CheckingAccount and...
what is the solution of this code? Also how would I run it in python to...
what is the solution of this code? Also how would I run it in python to check? q = Queue() q.enqueue(10) q.enqueue(12) q.enqueue(15) for i in range(len(q)): → if len(q) % 2 == 0: → → q.enqueue(q.dequeue()) → else: → → q.dequeue() print(q)
my question is in python. My question is how to add post users to post gres...
my question is in python. My question is how to add post users to post gres in python
I used this code for my first draft assignment. My teacher told me not to add...
I used this code for my first draft assignment. My teacher told me not to add a decrypt function. I have the variable encryptionKey holding 16. I can simply negate encryptionKey with the - in front. Then I make one key change and all the code still works properly. How do I adjust this code? import csv import sys #The password list - We start with it populated for testing purposes passwords = [["yahoo","XqffoZeo"],["google","CoIushujSetu"]] #The password file name to store...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT