Now that we've launched our shuttle, let's use loops (iteration) to automate some tasks.
First, initialize variables to store the following arrays. Remember to use descriptive names.
['chicken', 'pork', 'tofu', 'beef', 'fish', 'beans']
['rice', 'pasta', 'corn', 'potato', 'quinoa', 'crackers']
['peas', 'green beans', 'kale', 'edamame', 'broccoli', 'asparagus']
['juice', 'milk', 'water', 'soy milk', 'soda', 'tea']
['apple', 'banana', 'more kale', 'ice cream', 'chocolate', 'kiwi']
forloop to assemble 6 meals.
If the shuttle gets hijacked by space pirates, the astronauts can activate a self-destruct sequence to provide some drama for the viewers at home.
In order to prevent a rogue astronaut from activating the code, it takes two crew members to begin the countdown. Each person must enter a different code, after which the computer will "zip" them together before overloading the engines.
for loop that combines two strings together, alternating the characters from each source.
string = "1234"and
otherString = "5678", then the output will be "15263748".
code1 = "ABCDEF"and
code2 = "notyet", then the output will be "AnBoCtDyEeFt".
ka = "LoOt"and
blam = "oku!", then the output will be
Update your code from part A to add user input and validation.
whileloop, ask the user to select the number of meals to assemble. Validate the input to make sure it is an integer from 1 - 6.
Modify your code to check each meal for kale. If present, after the meal output add, "Don't worry, you can have double chocolate tomorrow."