4 Replies - 1308 Views - Last Post: 04 October 2008 - 04:51 AM Rate Topic: -----

#1 j0nj0n  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-September 08

quick beginner questions

Posted 12 September 2008 - 11:01 PM

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 [])

Is This A Good Question/Topic? 0
  • +

Replies To: quick beginner questions

#2 Stutzbach  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 29
  • Joined: 06-July 08

Re: quick beginner questions

Posted 13 September 2008 - 07:10 AM

View Postj0nj0n, 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.

View Postj0nj0n, 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 [])


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)
Was This Post Helpful? 0
  • +
  • -

#3 james_L  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 28-August 08

Re: quick beginner questions

Posted 04 October 2008 - 02:29 AM

:ph34r: 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.....

# 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

Was This Post Helpful? 0
  • +
  • -

#4 james_L  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 28-August 08

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!"


Was This Post Helpful? 0
  • +
  • -

#5 james_L  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 28-August 08

Re: quick beginner questions

Posted 04 October 2008 - 04:51 AM

:^: :D I've got it! thanks anyway!

 


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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1