#!/usr/bin/python # Python example 1 # P. TenHoopen, 11/18/08 # ask the user for their name name = raw_input("Please enter your name: ") # give a welcome message and display the name print "Hello and welcome", name, "!" # print a blank line print # ask the user for a small number # make sure to use the int function to convert the raw input # otherwise you can't use it as a number and numerical tests will fail times = int(raw_input("Please enter a number between 1 and 10: ")) # check if user entered a zero if times == 0: print "Can't be zero. Try again to see the 'cool' stuff." # check if user entered a number greater than 10 # elif is short for "else if" elif times > 10: print "Can't be bigger than 10. Try again to see the 'cool' stuff." else: # show what the user entered print "You entered: ", times print # set the variable count to 1 # it will be used to count loop iterations count = 1 # loop while the loop counter is less than or equal to the number given by the user while count <= times: # show a short message for each loop iteration print count, name, "is cool!" # increase the loop counter count = count + 1 # display a blank line print # tell the user how many letters are in their name print "There are", len(name), "characters in your name." # show the first character of the name variable print "The first letter of your name is", name[0] # show the last character of the name variable print "The last letter of your name is", name[-1] print print "End of program."