View Single Post
Old 12-30-2011, 12:10 AM   PM User | #1
pwolf
New to the CF scene

 
Join Date: Dec 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
pwolf is an unknown quantity at this point
Unhappy stuck with python, please advise

so im trying to make it so that pressing enter without inputting any value, will break the loop, however, an empty string can be used because of
for i in range(len(x_str_array)):
x[i] = int(x_str_array[i])
bit.
Code:
'Exercise 7.3'

# modified program from exercise 7.2

a=1
z=""
while x !=z:
    x_str = raw_input('Enter Start,Stop,Increment: ')
    if x==z:
        break
    else:
        x_str_array = x_str.split(',') # splits the string where a comma pops up
        x = range(len(x_str_array)) # Preallocation step- makes x= the same length as x_str_array
        for i in range(len(x_str_array)):
            x[i] = int(x_str_array[i])
        a=x[0]
        b=x[1]
        c=x[2]
        for number in range(a,b,c):
            print "number:", number, " square:", number**2, " cube:", number**3
please advise me on this.

p.s yes i am a complete novie, haha

i thought maybe using an empty tuple or list or something, but that wouldn't work either.
pwolf is offline   Reply With Quote