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
#1
Hi! I need code a list "d" to plot the s x t graph. The list "d" must have six itens too but if user input a value greater "a" in the list this value must be 0 in according to the equation "d=x*0". This code is a simplified example. Can someone help me?

import matplotlib.pyplot
a=int(input("a=")
b=int(input("b=")
c=[0,1,2,3,4,5]
d=[]
x=0
while (x<=a):
    d=b*(a-x)
    x=x+50
else:
    d=x*0
    d.append(x) 
matplotlib.pyplot.title("Average Speed")
matplotlib.pyplot.plot(c,d)
matplotlib.pyplot.xlabel("t [s]")
matplotlib.pyplot.ylabel("s [mi]")
matplotlib.pyplot.show()   
Note
When I run the code it displays the following error message:
AttributeError: 'int' object has no attribute 'append'
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,350 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