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...
icon
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
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
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
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
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])
Transcribed Image Text:In [8] read_and_sort() Out [8]: enter 4 numbers 1 In [ ]: enter 4 numbers ([1, 2], [2, 1], [1])
Solution
Bartleby Expert
SEE SOLUTION
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
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…
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)
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
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY