Question

In: Computer Science

PYTHON Given a 2D array with the layout of the floor of a concert hall and...

PYTHON

Given a 2D array with the layout of the floor of a concert hall and the height (in dwillyinches, a logarithmic measurement of height) of each concert attendee, write a program that determines if every attendee can see the front stage. An attendee can see the front stage if they are strickly taller than all of the attendees in front of them.

Everyone can see the front-stage in the example below:

# FRONT STAGE
[[1, 2, 3, 2, 1, 1],
[2, 4, 4, 3, 2, 2],
[5, 5, 5, 5, 4, 4],
[6, 6, 7, 6, 5, 5]]

# Starting from the left, the 6 > 5 > 2 > 1, so all four of these attendees can see.
# 6 > 5 > 4 > 2 - so all four of these attendees can see
# FRONT STAGE
[[1, 2, 3, 20, 1, 1], 
[2, 4, 4, 3, 2, 2], 
[5, 5, 5, 10, 4, 4], 
[6, 6, 7, 6, 5, 5]]

# The 10 is in front of the 6 and blocking its view; also the 20 blocks the 3, 10, and 6.

Your program should print True if every number (i.e., attendee) can see the front-stage, and False if even a single number/attendee cannot.

Sample Input 1

3
1 2
4 5 
7 8 

Sample Output 1

True 

Sample Input 2

4 
2 0 0 0 6
3 1 1 1 6 
4 2 2 2 9
5 2 3 4 11

Sample Output 1

False

Solutions

Expert Solution

Please up vote ,comment if any query . Thanks for question .Be safe .

Note : check attached image for output ,code compiled and tested in Spyder python3.

Program :

#function takes 2d list and number of rows as input
#return true or false if concert hall siting is valid returns true
def concert(Array,length):
j=0#column index
for j in range(len(Array[j])): #from 0 to total column
for i in range(length-1): #from 0 to length(total row)-1
#if current element greater or equal to next element return false
#because next element due to less height than current element
#can not see concert stage
#return False
#else after end of loop scanning return True
if Array[i][j]>=Array[i+1][j]:#
return False
j+=1#increment column number
return True#if all have valid height can see stage return true
  

#main program function starts from here
if __name__=="__main__":
  
DataList=[] #empty list
row=int(input()) #get number of rows
for i in range(row):#run a loop from 0 to row
string=input() #get a space separated string from user
userInputList=string.split() #split it by space in list type
userInputList=[int(i) for i in userInputList]#traverse list and convert it into integer
DataList.append(userInputList)#append new list to DataList
print(concert(DataList, row))#pass DataList as 2dList and number of rows
  

Program :

Output :

Please up vote ,


Related Solutions

Given a 2D array a, sum up ALL the edges of the array. Ex. int a[...
Given a 2D array a, sum up ALL the edges of the array. Ex. int a[ ][ ] = { {1, 2, 3, 4},                        {5, 6, 7, 8},                        {9, 10, 11, 12} }; OUTPUT: Sum of the edges = 65
A music conservatory has two concert halls. One concert hall had a pipe organ that was...
A music conservatory has two concert halls. One concert hall had a pipe organ that was in poor repair, and the other had no organ. The conservatory decided to buy a new organ for its concert hall with no organ. After some negotiation, the conservatory entered into a contract with a business that both repairs and sells organs. Under the contract, the business agreed to sell a new organ to the conservatory for its concert hall for $225,000 and would...
A chandelier with mass mmm is attached to the ceiling of a large concert hall by...
A chandelier with mass mmm is attached to the ceiling of a large concert hall by two cables. Because the ceiling is covered with intricate architectural decorations (not indicated in the figure, which uses a humbler depiction), the workers who hung the chandelier couldn't attach the cables to the ceiling directly above the chandelier. Instead, they attached the cables to the ceiling near the walls. Cable 1 has tension T1T1T_1 and makes an angle of θ1θ1theta_1 with the ceiling. Cable...
The Peacock Concert Hall is the gem of the community offering local and national acts to...
The Peacock Concert Hall is the gem of the community offering local and national acts to the community. Through gifts from its donors, the management continually strives to renovate its facilities and improve its processes. Write algorithms for the following scenarios. Desk-check your algorithm with at least 3 values. Include your algorithm and evidence of your desk-checks in your submission. 4. Sales. The concert hall manager wants to a calculate monthly ticket sale total by entering daily sales total for...
Python please: Given a 1D array with blank as non-obstacles and * as an obstacle, the...
Python please: Given a 1D array with blank as non-obstacles and * as an obstacle, the Dino can either traverse 1 at a time or jump minJump to maxJump spaces, can the Dino make it from the start of the array to end? [ * , , , ] regardless of input False (Dino dies on index 0) [ , , , , *] regardless of input False (Dine can never reach the end) [] True (Dino has nothing to...
few problems example of array and 2d array and the solution code in java language. I...
few problems example of array and 2d array and the solution code in java language. I am new to java and trying to learn this chapter and it is kinda hard for me to understand.
A musician in a concert hall is tuning her wind instrument. When she plays a short...
A musician in a concert hall is tuning her wind instrument. When she plays a short note she hears the echo of the note return from the opposite side of the 50.0 meter long auditorium 0.294 seconds later. Model the instrument as a tube closed at one end, if the instrument is properly tuned the note of the musician played would have a frequency of 233.082 Hz, but instead has a frequency of 226.513 Hz. This note is the first...
A musician in a concert hall is tuning her wind instrument. When she plays a short...
A musician in a concert hall is tuning her wind instrument. When she plays a short note she hears the echo of the note return from the opposite side of the 50.0 meter long auditorium 0.294 seconds later. Model the instrument as a tube closed at one end, if the instrument is properly tuned the note of the musician played would have a frequency of 233.082 Hz, but instead has a frequency of 226.513 Hz. This note is the first...
A concert hall has 9,000 seats and two categories of ticket​ prices, ​$26 and ​$46. Assume...
A concert hall has 9,000 seats and two categories of ticket​ prices, ​$26 and ​$46. Assume that all seats in each category can be sold. Concert 1 2 3 Tickets sold 9,000 9,000 9,000 Return required ​$274,000 ​$254,000 ​$411,000 a. How many tickets of each category should be sold to bring in each of the returns indicated in the​ table? ​$26 Tickets ​$46 Tickets Concert 1 ______. ______ Concert 2 ______ ______ Concert 3 ______. ______
Please make an Array-based implementation of a Binary Tree in Python based on the given file...
Please make an Array-based implementation of a Binary Tree in Python based on the given file below. Make sure to keep the Abstract Data File of the starter code below when building the Array-based implementation. Python Starter Code Given Below: class ArrayBinaryTree(BinaryTree): """Linked representation of a binary tree structure.""" # -------------------------- nested _Node class -------------------------- class _Node: def __init__(self, element, parent=None, left=None, right=None): # -------------------------- nested Position class -------------------------- class Position(BinaryTree.Position): """An abstraction representing the location of a single element."""...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT