[Tutor] [newb] ascii questions

justinstraube at charter.net justinstraube at charter.net
Sat Dec 13 13:48:39 EST 2003


Hello Tutors,

Im working on this and am running into a couple problems I can't figure 
out. Can anyone offer any hints or anything?

My questions follow this little bit

import random
def process(val):
    r = val + random.randint(n, amnt)
    if r < 0:
        r = r + 26
    elif r > 26:
        r = r - 26
    return r
count = 0
name = Uname = raw_input('What is your name? ')
while 1:
    #user # as an int and verifies its in range
    amnt = int(raw_input('Number 1 to 26? '))
    if amnt > 26:
        print 'That number is out of range'
        continue
    else:
        #negetive user #
        n = -amnt
        break
#processes the users name 5 times
while count < 6:
    #assigns the values of names
    name = Uname
    xname = ''
    #gets 1st characters value
    for x in name:
        name_x = ord(name[0])
        #uppercase
        if name_x >= 65 and name_x <= 90:
            name_x = name_x - 65
            x = process(name_x) + 65
        #lowercase
        elif name_x >= 97 and name_x <= 122:
            name_x = name_x - 96
            x = process(name_x) + 96
        #if name[0] is a [space]
        elif name_x == 32:
            x = 32
        name = name[0:]
        #adds the values character to the processed name
        xname = xname + chr(x)
    count = count + 1
    print xname
    if count == 6:
        print
        print 'Hit Enter for more'
        print 'Or ctrl-c to quit'
        raw_input()
        count = 0


Im not sure where the problem is in here. When I enter a name with all 
lower case and a lower number for amnt I get back the results I am 
expecting.




More information about the Tutor mailing list