Python Worksheet 1 Strings and Variables
Python Worksheet 1 Strings and Variables
1. Add three more, very similar lines of code to do the following: (Be careful with the spelling
of the syntax.)
Save and run your new program by pressing F5. Debug it if it contains any errors.
print ("Hello,",firstname,surname)
3. The following line of code will print the first character in each of the firstname and surname
variables. Python starts counting at 0, so “Tom” would be T=0, o=1 and m=2.
4. Declare another variable called fullname. Make this equal to firstname + surname. What do
you think the +" " does in the code below?
5. The code print(firstname.upper()) would print the user’s name in capital letters. Write a line
of code to print the surname in capitals, followed by the first name.
6. The code len(firstname) would return the number of letters in the user’s first name. Write
some code that would tell the user how many letters were in their surname.
7. Write some code that would create a new variable to hold a username for a login system.
The username must be created from the first three letters of the user’s surname, followed
by their first initial, followed by the length of their surname. E.g. Jack Smith would have the
username smij5. Hint: Use str(len(surname)) for this exercise.