Welcome to Dream.In.Code
Getting Help is Easy!

Join 132,688 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,291 people online right now. Registration is fast and FREE... Join Now!




quick beginner questions

 
Reply to this topicStart new topic

quick beginner questions, ask away, everyone

j0nj0n
post 12 Sep, 2008 - 10:01 PM
Post #1


New D.I.C Head

*
Joined: 2 Sep, 2008
Posts: 1

alright, the final project has to be some sort of letter scrambler, keeping the letter ranges in the same word of the sentence.
right now I have 1 raw_input as a, and got a random number between 0 and length of a-1.
I append that to z as a[r], and remove it from a as a[r] so its not chosen again, and make length of a -1, all inside a loop.

a.remove(a[r])
AttributeError: 'str' object has no attribute 'remove'

do i need to make string a into a list/tuple? if so, how so?

--------------------------------------------
to know when a sentence starts or ends, can i do something like if a[x] ==" " inside a loop, record its position with x, and place it in that same position in the final producT?
How would i go around to later place each" " at their positions in z?(z is a [])
User is offlineProfile CardPM

Go to the top of the page

Stutzbach
post 13 Sep, 2008 - 06:10 AM
Post #2


New D.I.C Head

*
Joined: 6 Jul, 2008
Posts: 10



Thanked 3 times
My Contributions


QUOTE(j0nj0n @ 13 Sep, 2008 - 12:01 AM) *

do i need to make string a into a list/tuple? if so, how so?


"a_list = list(a)" will convert a string to a list, but see below for another approach that may be helpful.

QUOTE(j0nj0n @ 13 Sep, 2008 - 12:01 AM) *

to know when a sentence starts or ends, can i do something like if a[x] ==" " inside a loop, record its position with x, and place it in that same position in the final producT?
How would i go around to later place each" " at their positions in z?(z is a [])


Check out the .split() and .join() methods for strings. I think you will find them very helpful.

word_list = a.split()
s = ' '.join(word_list)
User is offlineProfile CardPM

Go to the top of the page

james_L
post 4 Oct, 2008 - 01:29 AM
Post #3


New D.I.C Head

*
Joined: 28 Aug, 2008
Posts: 13


My Contributions


ph34r.gif okay I'm VERY new to python and i'm still in the dark but I have been able to make some basic programs, i stumbled across this code and i was wondering how to use uppercase and lowercase characters to make a decision in a program.....

CODE

# Area calculation program

print “Welcome to the Area calculation program”
print “–––––––––––––”
print

# Print out the menu:
print “Please select a shape:”
print “1.  Rectangle”
print “2.  Circle”

# Get the user’s choice:
shape = input(“> “)

# Calculate the area:
if shape == 1
    height = input(“Please enter the height: “)
    width = input(“Please enter the width: “)
    area = height*width
    print “The area is”, area
else:
    radius = input(“Please enter the radius: “)
    area = 3.14*(radius**2)
    print “The area is”, area


okay i tried doing this
CODE

# Area calculation program

print “Welcome to the Area calculation program”
print “–––––––––––––”
print

# Print out the menu:
print “Please select a shape:”
print “<a>  Rectangle”
print “<b>  Circle”

# Get the user’s choice:
shape = input(“> “)

# Calculate the area:
if shape == a || shape == A   #<========= here's my problem
    height = input(“Please enter the height: “)
    width = input(“Please enter the width: “)
    area = height*width
    print “The area is”, area
else:
    radius = input(“Please enter the radius: “)
    area = 3.14*(radius**2)
    print “The area is”, area


and obviously ran to an error i was guessing......

This post has been edited by james_L: 4 Oct, 2008 - 01:31 AM
User is offlineProfile CardPM

Go to the top of the page

james_L
post 4 Oct, 2008 - 03:27 AM
Post #4


New D.I.C Head

*
Joined: 28 Aug, 2008
Posts: 13


My Contributions


okay never mind the previous question I'm trying to loop my program but i've been unsuccessful at it ...... please help what can i do?

CODE

print "Area Calculation"
print "-----------"
print


print "please select a shape"
print "1  Rectangle"
print "2  Circle"

shape = input (">")
  



if shape ==  1:

    width = input ("enter width = ")
    height = input ("enter height = ")
    area = width*height
    print "this is the area of the Rectangle = ",area
    print
    choice = input ("Try again? <1> yes <2> no >>")

elif shape == 2:
    radius = input("please enter radius: ")
    area = 3.14*(radius**2)
    print "the area is", area
    print
    choice = input ("Try again? <1> yes <2> no >>")

else:
    print "invalid selection!"
    print
    choice = input ("Try again? <1> yes <2> no >>")

while choice != 2:

    if choice == 1:
        shape = input("select shape <1> rectangle <2> circle")

    elif  choice == 2:
        print "good-bye!"
User is offlineProfile CardPM

Go to the top of the page

james_L
post 4 Oct, 2008 - 03:51 AM
Post #5


New D.I.C Head

*
Joined: 28 Aug, 2008
Posts: 13


My Contributions


icon_up.gif biggrin.gif I've got it! thanks anyway!

CODE



choice = 0

while choice != 2:

    print
    print "Area Calculation"
    print "-----------"
    print


    print "please select a shape"
    print "1  Rectangle"
    print "2  Circle"

    shape = input (">")
  



    if shape ==  1:

        width = input ("enter width = ")
        height = input ("enter height = ")
        area = width*height
        print "this is the area of the Rectangle = ",area
        print
        choice = input ("Try again? <1> yes <2> no >>")

    elif shape == 2:
        radius = input("please enter radius: ")
        area = 3.14*(radius**2)
        print "the area is", area
        print
        choice = input ("Try again? <1> yes <2> no >>")

    else:
        print "invalid selection!"
        print
        choice = input ("Try again? <1> yes <2> no >>")



    if  choice == 2:
        print "good-bye!"
    
        


or.....

CODE


choice = True


while choice == True :

    print
    print "Area Calculation"
    print "-----------"
    print


    print "please select a shape"
    print "1  Rectangle"
    print "2  Circle"

    shape = input (">")
  



    if shape ==  1:

        width = input ("enter width = ")
        height = input ("enter height = ")
        area = width*height
        print "this is the area of the Rectangle = ",area
        print
        choice = input ("Try again? <1> yes <2> no >>")

    elif shape == 2:
        radius = input("please enter radius: ")
        area = 3.14*(radius**2)
        print "the area is", area
        print
        choice = input ("Try again? <1> yes <2> no >>")

    else:
        print "invalid selection!"
        print
        choice = input ("Try again? <1> yes <2> no >>")

    if choice == 1:
        choice = True

    elif  choice == 2:
        print "good-bye!"
        choice = False
        
    else:
        print "invalid Selection!"
        choice = True
        











This post has been edited by james_L: 4 Oct, 2008 - 04:49 AM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:31AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month