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

Pages: 1-

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-09 1:09

I see no question marks.

Name: OP 2009-03-09 1:16

>>2
Sorry, I figured the problem was something obvious.
Basically, the script stops telling me there's an error in the line "hd_list=[]" whenever I input the first variable when the script is running. Do I need parenthesis between the square brackets? Or is it some other obvious fucking mistake?

Name: Anonymous 2009-03-09 1:26

Python's white space destroys the idea of code optimisation, learn a real language, like Scheme.

Name: FrozenVoid !.FrOzenBUA 2009-03-09 2:31

use warnings;
use strict;

sub input {
    print @_;
    chomp(my $line = readline STDIN);
    $line
}

my @hd_list;
$hd_list[0] = input 'Capacity of first HD in gigs: ';
$hd_list[1] = input 'Price of first HD in USD: $';
$hd_list[0] = input 'Capacity of second HD in gigs: ';
$hd_list[1] = input 'Price of second HD in USD: $';

Name: FrozenVoid 2009-03-09 3:39

>>5
.......strange, this doesn't look like python.......



_____________________________
It is better to remain silent and be thought a fool, then to speak and remove all doubt.

Name: Anonymous 2009-03-09 3:57

INSANE-PRIEST--INSANE-PRIEST--INSAN
I___________,.-------.,____________I Python
N______,;~'_____________'~;,_______N fucking
S____,;___PYTHON FUCKING____;,_____S sucks
A___;___SUCKS, YOU FUCKING____;____A
N__,'______/PROG/ RETARDS.____',___N GvR
E_,;___GET IT INTO YOUR HEAD___;,__E is a
-_;_;______._____l_____.______;_;__- cocksucker
P_l_;____________l____________;_l__P
R_l__`/~"_____~"_._"~_____"~\'__l__R Python
I_l__~__,-~~~^~,_l_,~^~~~-,__~__l__I fucking
E__l___l________}:{__ (O) _l___l___E sucks
S__l___l_ (o) _/_l_\_______!___l___S
T__.~__(__,.--"_.^._"--.,__)__~.___T GvR
-__l_____---;'_/_l_\_`;---_____l___- is a
-___\__._______V.^.V___((oo))./____- cocksucker
I__O_VI_\________________ll_IV___O_I
N_____I_lT~\___!___!___/~ll_I______N Fucking
S_____I_l`IIII_I_I_I_IIIIll_I__o___S forced
A_O___I__\,III_I_I_I_III,ll_I______A indentation
N______\___`----------'__ll/____o__N will
E____O___\___._______.___ll________E this
-_________\..___^____../(_l___O____- ever
P_________/_^___^___^_/__ll\_______P fucking
R_O______/`'-l l_l l-';__ll_l___O__R WORK?!
I_______;_`'=l l_l l='__/ll_l______I
E_____O_l___\l l~l l__l/_ll_l______E Your mother
S_______l\___\ l_l l__;__ll_l__O___S was good
T__o____l_\___ll=l l==\__ll_l______T in bed, she
-____o__l_/\_/\l_l l__l`-ll_/______- grunts like
-_______'-l_`;'l_l l__l__ll_____O__- an ape.
I_O_______l__l l_l l__l__ll________I
N____O____l__l+l_l+l__l__ll___O____N GvR
S_________l__"""_"""__l__ll________S is a
A__O______l____o_o____l__ll____O___A cocksucker
N_________l,;,;,;,;,;,l__ll________N
E_____O___`lIlIlIlIlIl`__ll________E
-__________llIlIlIlIll___ll_____O__- By FV
P__________`"""""""""`___""________P (c)2003 Trollkore
-INSANE-PRIEST--INSANE-PRIEST--INSAN

Name: Anonymous 2009-03-09 4:13

>>1
You cannot expand lists in Python implicitly like you do in, for example, Javascript. When appending to a list, use list.append(...).

Besides, why not do this:
hd_list = [
float(raw_input("Capacity of first HD in gigs: ")),
float(raw_input("Price of first HD in USD: $")),
float(raw_input("Capacity of second HD in gigs: ")),
float(raw_input("Price of second HD in USD: $")) ]


Also use raw_input instead of input. The latter is for evaluating python code, which in most cases you will not want. The latter returns exactly the string you typed.

Name: Anonymous 2009-03-09 4:35

>>8


See guys, this is why you learn lower level languages first. Try doing that 'implicit expansion' shit in C and see if you don't get a memory access error, motherfucker.

Name: OP 2009-03-09 4:58

>>8
Thanks that fixed everything. I didn't know I could make the inputs part of the list like that, and trying it never occured to me. Also, the reason I was using "input" over "raw_input" was because the way all the tutorials make it seem is that "input" is designated for integers and/or numbers in general, and that "raw_input" is reserved for only strings involving alphabetical characters. Now I know I was very wrong in that assumption, thank you so much for taking the time to help me.
>>5
I do appreciate that effort you put in there, how ever that does look to me like Javascript, though my knowledge of code is severely lacking and I am most likely very wrong. However I am next to certain that it is not Python, which is most definitely what I stated (multiple times in fact) that I was working with.
So maybe next time, read before you post, it might not mark you off as a troll in everyone's books. ALSO: see the signature on >>6

Name: Anonymous 2009-03-09 4:58

>>6
( ≖‿≖)

Name: Anonymous 2009-03-09 21:17

>>10
>Javascript

( ≖‿≖)

Name: Anonymous 2009-03-09 21:51

>>10
A brilliant! example of Meta-trolling.

Truly an example for the ages.

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.

Name: OP 2009-03-10 5:30

>>14

Though I already used the first example given to solve my problem I do thank you for your help in the matter or rather the effort you put forth. And the .append() part I shall take into account for any further scripting, as I can most certainly see how it will be useful. Thank you for taking the time to help a n00b such as myself.

Name: Anonymous 2009-03-10 8:02

>>15
By the way, no-one here really hates Python.

Name: Anonymous 2009-03-10 8:03

>>16
Or any language. We are software development professionals!

Name: Anonymous 2009-03-10 8:14

>>17
No professional software developers are here

Name: Anonymous 2009-03-10 9:40

>>18
I receive $60k per year as an ENTERPRISE TURKEY SOLUTIONS DEVELOPER*


_________________________________________
*This is actually true.

Name: Anonymous 2009-03-10 10:10

Name: Anonymous 2009-03-11 19:47

>>>/b/122932151
Sorry for stealing this thread but its python too and /b/ has failed me.

Name: Anonymous 2009-03-11 19:52

>>21
404?

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