Related questions
In Python, Given the 2D list below, convert all values to 255 if they are above a threshold or to 0
if they are below. The threshold value is given as input by the user
a =[[77,68,86,73],[96,87,89,81],[70,90,86,81]]
Code
a =[[77,68,86,73],[96,87,89,81],[70,90,86,81]] # 2d array
#printing the orignal matrix
print("Orignal matrix is:")
for i in range(len(a)):
for j in range(len(a[i])):
print(a[i][j]," ",end='')
print('\n')
n= int(input("Enter a threshold value: ")) #user input threshold value
#setting value to threshold
for i in range(len(a)):
for j in range(len(a[i])):
if a[i][j]>n:
a[i][j]=255
else:
a[i][j]=0
print("New matrix is:")
#printing the changed matrix
for i in range(len(a)):
for j in range(len(a[i])):
print(a[i][j]," ",end='')
print('\n')
Computer Science homework question answer, step 1, image 1
Step by stepSolved in 2 steps with 2 images
- Can you use Python programming language to to this question? Thanksarrow_forwardWrite a Python program that reads from user the names and temperatures of n cities (n must be> 0) into two lists: a list to hold the names of the cities and another one to store the temperatures of each city. Then using these two lists, your program should find and display the following information as shown in sample output below: The average temperature of all cities The names and temperatures of cities with their temperature above the average The names and temperatures of cities with their temperature below the average. Enter number of cities (n) : 6 The average temperature is 34.167 Enter name and temperature of city 1: Muscat 32 Cities with temperature above average are: Nizwa Sur Sohar Musandam Enter name and temperature of city 2: Nizwa 35 35.0 40.0 Enter name and temperature of city 3: Sur 40 42.0 38.0 Enter name and temperature of city 4: Salalah 18 Cities with temperature above average are: Enter name and temperature of city 5: Sohar 42 Muscat Salalah 32.0 18.0 Enter name and...arrow_forwardGiven 2 integers as 2 lists of their digits, you have to compute their sum and output it as a list of its digits. If the integer is 1234 its corresponding list would be [1, 2, 3, 4]. You can assume the integers are non-negative. Input: [1, 2, 3, 4] [4, 3, 2, 1] output: [5, 5, 5, 5] Explanation: 1234 +たす 4321 =わ 5555 input: [9, 9, 9, 9] [1, 1, 1] output: [1, 0, 1, 1, 0] Explanation: 9999 +たす 111 =わ 10110arrow_forward
- Using c++ Contact list: Binary Search A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name. Define and call the following function. The return value of FindContact is the index of the contact with the provided contact name. If the name is not found, the function should return -1 This function should use binary search. Modify the algorithm to output the count of how many comparisons using == with the contactName were performed during the search, before it returns the index (or -1). int FindContact(ContactInfo contacts[], int size, string contactName) Ex: If the input is: 3 Frank 867-5309 Joe...arrow_forwardGiven an initialized two-dimensional list X and two variables i and j. Write an expression to assigne an float value from the keyboard to the i-th element of the j-th row. code in pythonarrow_forwardUsing python and sys.argv Create a program inrange.py that has a function that takes one integer argument. The function will print a list of all values between 5000 and 8000 that is divisible by (1) the integer argument, and (2) the argument + 4.arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education