Question

In: Computer Science

PYTHON LANGUAGE PLEASE DO NUMBER 5 ONLY """ # 1. Based on Textbook R6.28 # Create...

PYTHON LANGUAGE

PLEASE DO NUMBER 5 ONLY

"""
# 1. Based on Textbook R6.28
# Create a table of m rows and n cols and initialize with 0
m = 3
n = 4

# The long way:
table = []
for row in range(m) :
table.append([0]*n)   

# The short way:

# 2. write a function to print the table in row, column format,
# then call the function
'''
# using index
def printTable(t):
for i in range(len(t)) : # each i is an index, i = 0,1,2
for j in range(len(t[i])) : # j = 0,1,2,3
print(t[i][j], end=' ')
print()
'''
# without index:
def printTable(t):
for row in t :
for col in row :
print(col, end=' ')
print()
print()

printTable(table)


# what does the following print?

for i in range(m):
for j in range(n):
table[i][j] = i + j

printTable(table)
'''
Answer:
print: from these index values:
0 1 2 3 [0,0] [0,1] [0,2] [0,3]
1 2 3 4 [1,0] [1,1] [1,2] [1,3]
2 3 4 5 [2,0] [2,1] [2,2] [2,3]
'''
  
# 3. copy table to table2
table2 = copy.deepcopy(table)

'''
table2 = table => table2 is another reference to the same mem location
table2 = table.copy() => shallow copy
only copy the 1D list (outer list) of references,
which has row1 - row4 references
table => [ row1 => [ , , , ]
row2 => [ , , , ]
row3 => [ , , , ]
row4 => [ , , , ]
]
'''
  
table[0][0] = -1 # will table2 be changed? No
printTable(table2)


# 4. fill elements of bottom row of table2 with -1's
# and all elements of left col of table2 with 0's

for i in range(len(table2[-1])) :
table2[-1][i] = -1
  
for i in range(len(table2)) :
table2[i][0] = 0
  
printTable(table2)
"""
"""
# 5. We start with a dictionary of student ids and associated gpa's
d = {123:3.7, 456:3.8, 789:2.7, 120:2.8}
print(d)

# create a list of sid list and a tuple of gpa from d

# create a list of tuples (k,v) from d

# How do you construct a dictionary from a list of tuples?


# How do you construct a dictionary from the list of id and gpa?


"""

Solutions

Expert Solution

Request : Please increase your Brightness...above images are only for comments...

Code:

Output:


Related Solutions

Python Language Only! Python Language Only! Python Language Only! Python 3 is used. When doing this...
Python Language Only! Python Language Only! Python Language Only! Python 3 is used. When doing this try to use a level one skill python, like as if you just learned this don't use anything advanced if you can please. If not then do it as you can. Assume you have a file on your disk named floatnumbers.txt containing float numbers. Write a Python code that reads all the numbers in the file and display their average. Your code must handle...
By only importing multiprocessing Write a python program which do the following : 1- Create one...
By only importing multiprocessing Write a python program which do the following : 1- Create one process this process must-read the content of a file “read any file content exist in your machine” and after that create another process in the first process function which will get the file content as a parameter for the second process function. 2- The second process function will get the file content and check out if there are any special characters or numbers in...
In Python please:  Number the Lines in a File: Create a program that adds line numbers to...
In Python please:  Number the Lines in a File: Create a program that adds line numbers to a file. The name of the input file will be read from the user, as will the name of the new file that your program will create. Each line in the output file should begin with the line number, followed by a colon and a space, followed by the line from the input file.
please create a tic tac toe game with python using only graphics.py library
please create a tic tac toe game with python using only graphics.py library
Python question Recall that a prime number is an integer that is only divisible by 1...
Python question Recall that a prime number is an integer that is only divisible by 1 and itself. For example, numbers 2, 3, 5, 7, 13, 19 are prime, whereas 4, 10, 12, 100 are not. Also, recall that factors are the numbers you multiply to get another number. For example, 24 has 8 factors: 1, 2, 3, 4, 6, 8, 12, and 24. As you know, any number can be factorized into several (possibly repeating) prime factors. For instance,...
Please Solve with c language Create 5-by-5 integer array. Initialize the elements of the array starting...
Please Solve with c language Create 5-by-5 integer array. Initialize the elements of the array starting from 1. Your element [0][0] should be equal to 1; element[4][4] should be equal 25. Print the array. The output should have 5 rows and 5 columns. Specify the width for each output to demonstrate the table in a formatted view. Change the value of the elements: 2nd row 4th column to 24, 1st row 3rd column to 13. Print the array again. Find...
The programming language is Python Instructions: Create a function that will delete a node in a...
The programming language is Python Instructions: Create a function that will delete a node in a Linked List based on position number. On below example, if you want to delete position #2, it will remove the Banana (arrangement of nodes below is Apple, Banana, Cherry, Grapes, Orange). myLinkedList = LinkedList() myLinkedList.append("Banana") myLinkedList.append("Cherry") myLinkedList.append("Grapes") myLinkedList.append("Orange") myLinkedList.prepend("Apple") myLinkedList.deleteByPositionNum(2) node = myLinkedList.head while node: print(node.value, " ") node = node.next_node You may start with the function head: def deleteByPositionNum(self, positionNum):
Python language!!!!! №1 The translation from the Berland language into the Birland language is not an...
Python language!!!!! №1 The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if...
Python Language: Similar to Project 3, write a program that loops a number from 1 to...
Python Language: Similar to Project 3, write a program that loops a number from 1 to 10 thousand and keeps updating a count variable according to these rules: if the number is divisible by n1, increase count by 1 if the number is divisible by n2, increase count by 2 if the number is divisible by n3, increase count by 3 if none of the above conditions match for the number, increase count by the number. Before the loop begins,...
5. A prime number is a number that is only evenly divisible by itself and 1....
5. A prime number is a number that is only evenly divisible by itself and 1. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, how‐ ever, is not prime because it can be divided evenly by 1, 2, 3, and 6.   Write a Boolean function named is_prime which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT