Python Forum
List and function while and else
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List and function while and else
#3
(Oct-08-2019, 06:27 PM)ichabod801 Wrote: I think if you had more descriptive variable names you might figure this out for yourself. You initialize d to a list on line 4, then change it to an integer on lines 7 and 10, and then try to append to it on line 11. It seems like you are mixing d up with something else when you assign integers to it. The else clause is unclear. You have no break statement, so it will always trigger. But it will only run after the while loop is finished, so even if the other problems are fixed, d will only ever have one item in it.

I'm coded break. The graph is now being generated, but another error message has displayed.

a=int(input("a="))
b=int(input("b="))
c=[0,1,2,3,4,5]
d=[]
x=0
while (x<=a):
    x=x+50
    d=b*(a-x)
    break
else:
    x=0
d.append(x) 
ValueError: x and y must have same first dimension, but have shapes (6,) and (1,)
Reply


Messages In This Thread
List and function while and else - by doug2019 - Oct-08-2019, 06:10 PM
RE: List and function while and else - by doug2019 - Oct-08-2019, 06:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I created a function that generate a list but the list is empty in a new .py file mrhopeedu 2 2,359 Oct-12-2019, 08:02 PM
Last Post: mrhopeedu

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020