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 [])
quick beginner questionsask away, everyone
Page 1 of 1
4 Replies - 1123 Views - Last Post: 04 October 2008 - 04:51 AM
Replies To: quick beginner questions
#2
Re: quick beginner questions
Posted 13 September 2008 - 07:10 AM
j0nj0n, on 13 Sep, 2008 - 12:01 AM, said:
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.
j0nj0n, on 13 Sep, 2008 - 12:01 AM, said:
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 [])
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)
#3
Re: quick beginner questions
Posted 04 October 2008 - 02:29 AM
# 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
# 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: 04 October 2008 - 02:31 AM
#4
Re: quick beginner questions
Posted 04 October 2008 - 04:27 AM
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?
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!"
#5
Re: quick beginner questions
Posted 04 October 2008 - 04:51 AM
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.....
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: 04 October 2008 - 05:49 AM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|