Tutorial A3

1 Store the following lines in a suitable Python object while maintaining the indentation format:

Twinkle, twinkle, little star,
    How I wonder what you are!
        Up above the world so high,
        Like a diamond in the sky.

Twinkle, twinkle, little star,
    How I wonder what you are

Display the object on the screen.

2 Imagine you have a structure file from the RCS Protein Database (PDB) named "HSA-glucose_complexe.pdb". Store the file name in a Python variable. Extract the base name of the file and the file extension and store both in separate variables. Now substitute the underscore (_) in the file name with a space (" "). Hint: the file extension corresponds to the four last characters of the the file name.

3 “A nut for a jar of tuna” – could this be a palindrome? How would you check with Python? Remove whitespace and convert all letters to lowercase while you do! What about the words “lived” and “devils”? Maybe they are if your join them.

Advanced 1 Indentation is important in Python as we will see soon. It is recommended to use spaces instead of tabs. Imagine you have text stored as a string, where indentation is done using tabs (escape sequence \t). Use the expandtabs string method (find out how it works) to convert tabs into 4 spaces.

[1]:
code = (
    "Lorem ipsum dolor sit amet,\n"
    "\tconsectetur adipiscing elit,\n"
    "\tsed do eiusmod tempor incididunt ut labore\n"
    "et dolore magna aliqua."
    )
print(code)
Lorem ipsum dolor sit amet,
        consectetur adipiscing elit,
        sed do eiusmod tempor incididunt ut labore
et dolore magna aliqua.