a guest Apr 16th, 2018 68 in 8 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- Python Exercise 1
- You can write this in a fresh Python program, or use the interactive interpreter
- Create a tuple containing 'Jan', 'Feb' etc.
- Check you understand which index of the tuple contains 'April'
- Print the months in the third quarter of the year (Jul-Sep) using [n:m] and using [n:-m]
- Use 'input' to ask the user for a full name which you store in some global variable
- Force the name to title case using .title()
- Show them the reverse of whatever they typed by using [::-1]
- Store first_name and last_name by finding the index where the space occurs and getting the string up to
- and then following the space. Try using negative indexes for the second parameter
- Ask the user their birthday month, then their birth date ( e.g. 1-31 ) and then year ( e.g. 1972 )
- CAUTION: we currently have no way to check so only enter actual months (as they appear in your list)
- Derive the index of the month and use that to build a date-like construct ( e.g. 15/9/1972 )
- Create a list containing the entered names, date, month and year
- Use print() to show details nicely formatted ( e.g. first: Toby, last: Dussek, birthday: 15-9-1972 )
- Ask the user to enter a middle name/initial (make one up if you have none)
- Insert this value in it's place within the existing list
- Explore string.split(' ') as an alternative way to create a list from a series of entered words
- Explore mutating the list using del, remove() and pop()
- Find how many times a given letter ( e.g. 'e' ) appears in the name using .count('e')
RAW Paste Data