Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

moronic n00b needs help with python

Name: Anonymous 2009-03-09 1:07

I'm a trying to learn Python, I've lurked this board for a while so I already know the general hatred of python that goes on around here. But as far as I can tell it's the easiest for a first language, and too me it looks alot cleaner then Java or Perl. Also since, college is not exactly an option for me at this current time, I'm stuck teaching myself through online tutorials and shitty ebooks. But I ran into a snare in an early tutorial dealing with lists/tuples.

hd_list = []
hd_list[0] = float(input("Capacity of first HD in gigs: "))
hd_list[1] = float(input("Price of first HD in USD: $"))
hd_list[2] = float(input("Capacity of second HD in gigs: "))
hd_list[3] = float(input("Price of second HD in USD: $"))

I know its a fuck simple problem, but I can't figure it out.

nb4 read SICP
(also, my first post here, so I don't know the code tag, sorry)

Name: Anonymous 2009-03-10 0:50

>>10

If you're converting the input via float() anyway, why not always use raw_input() and save likely and possible errors.

Your first error came from the fact that you declared a list of size zero, and then tried to add values to it. When you declare it, you have to declare the size it is so if you did hd_list = [0,0,0,0] you'd have no problems.

You can also use the .append() function on lists:

hd_list.append(float(raw_input("TEXT: ")))

if you are unsure how big the list will be.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List