Question

Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a Python...

Python Language Only!!!!

Python Language Only!!!!

Python Language Only!!!!

Python 3 is used.

Write a Python statement that creates a two-dimensional list named values with 3 rows and 2 columns. Then write nested loops that get an integer value from the user for each element in the list. Then display the content of the list. Please see the outcome below:

Outcome run:

Enter the 1 element in the 1 row :1

Enter the 2 element in the 1 row :2

Enter the 1 element in the 2 row :3

Enter the 2 element in the 2 row :4

Enter the 1 element in the 3 row :5

Enter the 2 element in the 3 row :6

The content of the list is:

1 2

3 4

5 6

(Needs to look exactly like outcome for thumbs up)

0 0
Add a comment Improve this question Transcribed image text
Answer #1
  • 'str()' method ensures the int converted to str to get concatenated with the message.
  • since for loop iterates from 0 to 1 and 0 to 2, we have to print i+1 and j+1 for getting actual row count rather than list index.
  • 'end = " "' in a print statement ensures that the automatic newline after each print statement is skipped and space is printed in that place.
  • 'append()' method is for attending an element to a list.

Screenshot Of Code:

1 5 6 8- n = + # declare values as a list 2 values [] 3 # start a for loop to iterate through 3 rows 4- for i in range(3): #

Output:

Enter the 1 element in the 1 row:1 Enter the 2 element in the 1 row:2 Enter the 1 element in the 2 row:3 Enter the 2 element

Code to Copy:

# declare values as a list
values = []
# start a for loop to iterate through 3 rows
for i in range(3):
# initialize a row[] (empty list) to save values of current row that user is entering
row = []
# start a for loop to iterate through 2 columns
for j in range(2):
# get input from user and append the same to the end of current row
# format message using i and j to display current position of input
n = input('Enter the '+ str(j+1) +' element in the ' + str(i+1) + ' row:')
row.append(n)
# after iteration of each row append the row (row[]) to list values
values.append(row)
# print message for final output
print("The content of the list is:")
# iterate through each row of list using a for loop
for i in range(3):
# iterate through each column of list using a for loop
for j in range(2):
# print ith row jth column element end = " " skips new
# line after each print statement rather puts a space at the end
print(str(values[i][j]), end = " ")
# print a newline after each row iteration.
print()

Add a comment
Know the answer?
Add Answer to:
Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a Python...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a Python...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a Python statement that creates a two-dimensional list named values with 3 rows and 2 columns. Then write nested loops that get an integer value from the user for each element in the list. Then display the content of the list. Please see the outcome below: Outcome run: Enter the 1 element in the 1 row :1 Enter the 2 element in the 1 row :2...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a function...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a function named capital_letter that accepts a string as an argument and checks if each word in the string begins with a capital letter. If so, the function will return true, otherwise, return false. Please see the outcome below: Outcome number 1: Enter a string: Python Is Really Fun! True Sample run number 2: Enter a string: i Love Python False Note: Try to keep this...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a program...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a program that creates a dictionary named rooms containing course numbers and the room numbers of the rooms where the courses meet. The dictionary should have the following key-value pairs: Course Number (Key) Room Number (Value) CS101 3004 CS102 4501 CS103 6755 NT110 1244 CM241 1411 The program should also create a dictionary named instructors containing course numbers and the names of the instructors that teach...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a program...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a program that creates a dictionary named rooms containing course numbers and the room numbers of the rooms where the courses meet. The dictionary should have the following key-value pairs: Course Number (Key) Room Number (Value) CS101 3004 CS102 4501 CS103 6755 NT110 1244 CM241 1411 The program should also create a dictionary named instructors containing course numbers and the names of the instructors that teach...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a Python...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. Write a Python code that gets a string from the user and counts the number of uppercase letters, the number of lowercase letters, the number of digits, and the sum of the digits. Please see the outcome below: Outcome: Enter the string: okOKE9o7 Uppercase letters: 3 Lowercase letters: 3 Digits: 2 Sum of digits: 8 Must look exactly like outcome for full credit.

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is used. A. Write a function named smaller that accepts two arguments: a list, and a number n. Assume that the list contains numbers. The function should display all numbers in the list that are smaller than the number n. Write a code that declares and initializes a list of numbers and a variable number and pass them to the function to test it. Please see the outcome below:...

  • Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is sued. Write a Python...

    Python Language Only!!!! Python Language Only!!!! Python Language Only!!!! Python 3 is sued. Write a Python code that gets a string containing a person’s first, middle, and last name, and print her/his last name, followed by comma and the first name initial. For example, if the user enters Randy Rick Gomez, the program should display Gomez, R. Please note that in the output, the first character of each name should be capital. Please see the outcomes below: Outcome: Enter your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT