Your goal in this lab is to create a program that will input the user's first and last names separately and then greet them.
In addition, try running the example below and adding extra spaces before or after the name or using lowercase for the names.
Open GitHub Desktop and the Mad Libs repository
Open the repository in VS Code (or Codespaces)
Open lab3.py
The strip() method removes any leading (spaces at the beginning) and trailing (spaces at the end) whitespace characters from a string.
It's useful for cleaning up user input or textual data. Often, extra spaces can cause issues in string manipulation or when comparing strings.
The title() method converts the first character of each word in a string to uppercase and the rest to lowercase.
This is particularly useful for formatting names or titles in a standardized way.
Function chaining involves calling multiple functions in a single statement. In Python, you can chain methods by appending one method call after another, separated by periods. Chaining functions can make your code more concise and can also potentially improve performance by reducing the number of intermediate variables. However, it's essential to ensure that the code remains readable and maintainable.
Formatted string literals, or "f-strings", allow you to embed expressions inside string literals, using curly braces { }. They make it easier to concatenate and format strings. f-strings are often more readable and concise compared to other methods of string formatting.
With the four concepts learned above, complete the program which greets the user based on their first and last names
When done, test it to ensure it removes any extra whitespace and capitalizes the names
Then, save all of your work and close VS Code
Back in GitHub Desktop, commit with a meaningful comment. E.g. "Finished lab 3"
Push your code
Congratulations on finishing Lab 3, you can now:
Remove extra whitespace from strings
Convert strings to title case
Chain functions together for more concise code
Join strings using concatenation using another technique
Once again, from Harvard's CS50P if you feel like you need further explanation or have missed a lesson: