i cant work out whats wrong with my code, im trying to create a function where im using a list to store a series of numbers and then use a loop to store each number as a new element of my numbers then trying to order them and then create a square. ive tried to inout 4 numbers in so many different ways in the user interface and its not working !!
i cant work out whats wrong with my code, im trying to create a function where im using a list to store a series of numbers and then use a loop to store each number as a new element of my numbers then trying to order them and then create a square. ive tried to inout 4 numbers in so many different ways in the user interface and its not working !!
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
i cant work out whats wrong with my code, im trying to create a function where im using a list to store a series of numbers and then use a loop to store each number as a new element of my numbers then trying to order them and then create a square. ive tried to inout 4 numbers in so many different ways in the user interface and its not working !!
![File v
Save TimeTravel 5 C
Insert Cell Kernel Help
File Edit View
+
tab Code v
In [151]: def read_and_sort():
mynumbers=[]
for i in range (4):
for i in range (len (mynumbers1)):
X
mynumbers.append(input ("enter 4 numbers"))
mynumbers1=mynumbers[:]
In [154] read_and_sort()
Halt
for j in range (i+1, len (mynumbers1)):
if mynumbers1[i]<mynumbers1[j]:
a, b, c=read_and_sort()
print("original list", a)
print ("sorted list", b)
print ("square list", c)
M
Contents
Validate
Format >_ Console
mynumbers1[i], mynumbers1 [j] =mynumbers1[j], mynumbers1 [i]
mynumbers2=[]
for i in range (len (mynumbers)):
mynumbers2.append(mynumbers [i] *mynumbers[i])
return mynumbers, mynumbers1, mynumbers2
Print
CPU:
Snippets
Memory:
Notebook v 8
Trusted Python 3 (Ubuntu Linux) O
X
0.004 seconds 10
7.398 seconds 11](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F968956d8-8ca7-43f8-85c9-473f38582f2a%2F9a7ade9d-a38d-462b-af88-294c0560c1a3%2Fkdp68g_processed.png&w=3840&q=75)
Transcribed Image Text:File v
Save TimeTravel 5 C
Insert Cell Kernel Help
File Edit View
+
tab Code v
In [151]: def read_and_sort():
mynumbers=[]
for i in range (4):
for i in range (len (mynumbers1)):
X
mynumbers.append(input ("enter 4 numbers"))
mynumbers1=mynumbers[:]
In [154] read_and_sort()
Halt
for j in range (i+1, len (mynumbers1)):
if mynumbers1[i]<mynumbers1[j]:
a, b, c=read_and_sort()
print("original list", a)
print ("sorted list", b)
print ("square list", c)
M
Contents
Validate
Format >_ Console
mynumbers1[i], mynumbers1 [j] =mynumbers1[j], mynumbers1 [i]
mynumbers2=[]
for i in range (len (mynumbers)):
mynumbers2.append(mynumbers [i] *mynumbers[i])
return mynumbers, mynumbers1, mynumbers2
Print
CPU:
Snippets
Memory:
Notebook v 8
Trusted Python 3 (Ubuntu Linux) O
X
0.004 seconds 10
7.398 seconds 11
![In [154] read_and_sort()
enter 4 numbers 1
enter 4 numbers
TypeError
Traceback (most recent call last)
<ipython-input-154-db115feec9e3> in <module>
--> 1 read_and_sort()
<ipython-input-151-4f0c9d5e2860> in read_and_sort()
mynumbers2=[]
for i in range (len (mynumbers)):
mynumbers2.append(mynumbers [i]*mynumbers[i])
13
14
---> 15
16
17
TypeError: can't multiply sequence by non-int of type 'str'
return mynumbers, mynumbers1, mynumbers2
7.398 seconds](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F968956d8-8ca7-43f8-85c9-473f38582f2a%2F9a7ade9d-a38d-462b-af88-294c0560c1a3%2Fqaah7z_processed.png&w=3840&q=75)
Transcribed Image Text:In [154] read_and_sort()
enter 4 numbers 1
enter 4 numbers
TypeError
Traceback (most recent call last)
<ipython-input-154-db115feec9e3> in <module>
--> 1 read_and_sort()
<ipython-input-151-4f0c9d5e2860> in read_and_sort()
mynumbers2=[]
for i in range (len (mynumbers)):
mynumbers2.append(mynumbers [i]*mynumbers[i])
13
14
---> 15
16
17
TypeError: can't multiply sequence by non-int of type 'str'
return mynumbers, mynumbers1, mynumbers2
7.398 seconds
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
hi just did this and it worked however this is what happens, i am wanting to be able to input 4 numbers as a list and only 2 boxes come up. what should i do??
![In [8] read_and_sort()
Out [8]:
enter 4 numbers 1
In [ ]:
enter 4 numbers
([1, 2], [2, 1], [1])](https://content.bartleby.com/qna-images/question/968956d8-8ca7-43f8-85c9-473f38582f2a/c05f65e3-f269-4161-a7fc-2f5b440bd001/iky5oj4_thumbnail.png)
Transcribed Image Text:In [8] read_and_sort()
Out [8]:
enter 4 numbers 1
In [ ]:
enter 4 numbers
([1, 2], [2, 1], [1])
Solution
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY