A string is a word or several words stored as a program value. Put text inside quotation marks, such as "Welcome to Erik's Coffee Shop!". Strings are common arguments for functions such as print() and input(). section 1.2
Strings become useful immediately in a small coffee-shop application:
- Pass a string to print() to show a message. section 1.2
- Save a function's returned string in a variable, then use that variable later. section 1.2
- Remember that keyboard input arrives as a string; convert it before doing mathematical operations. section 2.1
Your coffee-shop order
name = input("Please enter your name: ") drink = input("Please enter your drink: ") print("Here is your order, ", name) print("Main product: ", drink) section 1.2
Listing 1.1 The first version of the coffee shop application
print("Welcome to Erik's Coffee Shop!")
name = input("Please enter your name: ")
drink = input("Please enter your drink: ")
flavor = input("Please enter your flavor: ")
topping = input("Please enter your topping: ")
print("Here is your order, ", name)
print("Main product: ", drink)
print("Flavor: ", flavor)
print("Topping: ", topping)
print("Thanks for your order!")
Use the complete coffee-shop listing to trace strings from prompts into variables and printed order details. section 1.2























