We won't do your homework for you. We have our own work and schoolwork to do. What we WILL do is help you along. Let's break down this program and define an algorithm:
step 1 - prompt user for name
step 2 - save name into a string variable
step 3 - separate string into characters
step 4 - traverse the string and look at each character individually
step 5 - convert each character to its numerical "equivalent"
step 6 - use an accumulator variable and increment it each time we evaluate a character
step 7 - output the accumulator variable as the final sum
Does that make sense to you? See if you can come up with some code converting that algorithm into python. We'll then be more than happy to help you further, but you have to show us effort on your part.
cscgal
The Queen of DaniWeb
19,424 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
Are you just counting letters, and they all have to be lower case?
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
Very nice thinking here, just needs a little touch up to work ...
[php]# using indexing
def main():
#name = raw_input("Enter your name in lower case letter")
# another option to get a lower case name
name = raw_input("Enter your name: ").lower()
# notice the space in front of 'a' this will give an index of a=1, b=2 and so on
# also gives a space an index of zero, so it won't count
letters = " abcdefghijklmnopqrstuvwxyz"
value = 0
for c in name:
print c, letters.find(c) # test
value = letters.find(c) + value
print "The numeric value of your name is", value
main()
[/php]
My original thought was to use the ASCII value of the lower case letters in the name. The function ord('a') would give 97 so you have to subtract 96 to get 'a'=1. Look at this code sample ...
[php]# using ASCII values
name = "Tamika Phai Mills".lower() # testing
sum = 0
for c in name:
# you want to count just letters, ord(c) give the ASCII value of the letter
if c.isalpha():
sum = sum + ord(c) - 96
print c, ord(c), ord(c) - 96, sum # test
print "result for '%s' = %d" % (name, sum)
"""
result for 'tamika phai mills' = 154
"""
[/php]
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
I think you're a little overanxious, butterflyTee. There is no need to keep bumping your thread with multiple posts. Additionally, I had to delete one of your threads because you posted in duplicate.
cscgal
The Queen of DaniWeb
19,424 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 230
I always looked at florida community college at jacksonville as just an ordinary java trenched school. How did Python get in there?
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
Let's not let this get off-topic. I'm going to close this thread before it gets too out of hand.
Some advice: Please keep ALL discussion on a single topic in one thread, and please don't spam the forum with all of your homework assignments.
alc6379
Cookie... That's it
2,820 posts since Dec 2003
Reputation Points: 186
Solved Threads: 147