138k views
1 vote
The bakery has requested the following custom variables:

-customer’s first name
-customer’s last name
-a coupon percentage off
-the date that they became a newsletter subscriber

Create an appropriate variable for each of these four items.

Then create string for the custom newsletter text that will show up before, between, and after each custom variable.

For example, “Hello,” might be the first string, followed by the variable carrying the customer’s name, followed by “Thanks for subscribing to our newsletter!” Your custom newsletter text should greet the person, then offer them a coupon, and then thank them for being a loyal customer.

Add placeholder names and information to populate into the variables for testing purposes by making up data for each. You can use your own name, for example, as this is simply a prototype or proof of concept. To do this, remember that the equals sign = between a variable and its value assigns that value to the variable.

Finally, use the print function to display the final newsletter text that includes all the required variables. This will display a final string that reads like a plaintext newsletter with the variables appropriately replaced by the defaults for each that you set in Step 1.

We can also combine two strings together in a single print function by using the + sign like this:

print(greetingTxt + firstName + bodyTxt1)

User Cuga
by
4.3k points

1 Answer

7 votes

Code:

firstName = "Bill"

lastName = "Nye"

coupon = 15

joinDate = "January 14, 1973"

print("Hello, " + firstName + lastName)

print("Thanks for subscribing to our newsletter!")

print("Here's a coupon for " + str(coupon) + "% off for being subscribed since " + joinDate)

Output:

Hello, BillNye

Thanks for subscribing to our newsletter!

Here's a coupon for 15% off for being subscribed since January 14, 1973

User Ashwin Singh
by
4.0k points