Skip to main content

01 | Strings and Basic Operations

Objective:

To understand fundamental concepts of string manipulation, quoting, and basic operations in Python.

Tasks:

1. String Quoting:

Create three strings with the print function. The first string should use single_quotes, the second should use double_quotes, and third should use triple_quotes. Include one sentence in the first two which makes sense to use each particular type of quotation set. It the case of the triple quote, use two or three sentences.

2. String Escaping:

Create a variable which is a sentence which contains an apostrophe (str). Use single quotations to enclose the string. Escape the (') using an escape character. Print the escaped_string.

3. Type Conversion and Casting:

Create variables num_string and num_int. Assign a string representing a number to num_string. Use type conversion to convert num_string to an integer and assign it to num_int. Print both num_string and num_int.

4. Input and Concatenation:

Prompt the user to enter their first name using the input() function. Store the input in a variable called first_name. Prompt the user to enter their last name using the input() function. Store the input in a variable called last_name. Concatenate first_name and last_name to create a full name and store it in a variable called full_name. Print full_name.

5. Using f-strings:

Create two variables with two different variable names. Assign one word to one variable and another word to the other variable. Use an f-string to print a sentence that includes these two variables.

6. Math:

Create a program which asks your user to input three different int numbers. (We won't worry with validating the numbers to ensure they are unique-yet) Store each int number as a variable. Write an expression which multiplies the first two numbers and then raises the product of those two numbers to the power of 2 (squares the number) then subtract the third number from the result of the previous operation.

7. Currency Formatting

Duplicate the previous task and make the numbers floats and then then print the result as currency.

8. Demo the end parameter

Consider the following:

print('Some text and')
print('some other text.')

Add necessary end parameter(s) to make the output read as follows:

Some text and some other text.

9. Demo the sep parameter

Print out this date with hyphens using the sep parameter.

print('01,'29','2024')