COMSC 100 Programming Exercises, For SP15 Programming is fun! Click HERE to see why. This set of exercises is designed for you to try out programming for yourself. Who knows maybe you ll be inspired to pursue study in computer science. At least you ll gain an appreciation for discipline, exactness, patience, and attention to detail that it takes to be a programmer. In any case, learning to program can help you develop problem- solving skills. As you go through these assignments, take the time to: understand the problem before you start doing any programming read all instructions first, complete one step at a time and make sure it s correct before starting the next step, know when to take your losses remember you can always start over if you get hopelessly lost, learn the difference between what you know and what you think you know that is, test your programs to make sure they work correctly, and they produce a desirable, professional result. In order to develop any useful understanding of programming, it is necessary to actually do some programming. That s what this series of exercises does it provides a structured, step- by- little- step sequence for learning basic programming steps. If you are diligent, read thoroughly, and precise, you will go easily from one exercise to the next, learning a bit more each time. Python The exercises in this series are designed using the Python computer programming language. You can create and execute Python programs using only an Internet browser, like Internet Explorer, Safari, Firefox, or Chrome. There are many other popular programming languages that could have been used instead, like C++ or Java, but most others involve installation and use of compiler software a step that complicates things a bit for beginners. Almost everyone knows how to use a browser, and that s all we ll need. To do our exercises, we ll use www.tutorialspoint.com/execute_python3_online.php, a freely available Python 3 compiler. But if you wish to use any other Python 3 compiler, you may do so. Whatever you use, you ll submit a text file for grading your instructor will tell you how to do that. If You Get Stuck You may struggle with some of these assignments, as is part of the learning process. When that happens do this: start the assignment over from scratch, and repeat this process until you complete the assignment without struggle. Do this before going to the next exercise, because each new exercise builds on what you learned from the previous ones. And click HERE for FAQs that may help you get unstuck. Online students: Contact your instructor for help before spending a lot of time in trial and error and becoming frustrated. Remember that this is supposed to be a positive experience of learning some basics of how computer programming works. There are many conceptual hurdles to overcome throughout this series of exercises, and your instructor is here to help you over them. Face- to- face students: These exercises are meant to be completed during the lab period of your regular scheduled class time, with the help and supervision of your instructor. Seek your instructor s help whenever you find yourself struggling with understanding the requirements of an exercise or if things are not working for you. These exercises are not really designed for you to do outside of class, on your own, so if you work on any at home and run into difficulty, bring it to class so that you can get it resolved. Comsc 100 Page 1 of 16 Programming Exercises
EXERCISE 1: Using The Internet Browser To Write And Execute Python Programs Purpose. The purpose of this exercise is for you to access the Internet page where your work for all of the exercises will be completed, and assure yourself that you ll be able to participate in this series. Requirements. On a Windows PC or on a Mac, open the Internet browser of your choice. Make sure you have access to the Internet, and go to this URL: www.tutorialspoint.com/execute_python3_online.php You should see something very much like this: Exploring. If so, you ll see that there is already a simple Python program typed in the box labeled main.py. You should see an icon. Click it to execute the program, and you should see this note Hello World! : See where it says Use this section to type your Linux commands? You ll use this for the one command you ll be entering in this series the clear command, as explained on page 3. So already you have seen what a Python program looks like, you ve executed a program, and seen what actual output looks like. Good start! Experimenting. Play around with this try typing different text in the print statement of the code, and execute observe the output. Add more print statements above or below the one with Hello World! see what output you can produce. Be sure to fully left-justify each print statement! HINT: To add another print statement, copy/paste/markup the existing print ("Hello World!") statement do not type it from scratch! This helps to avoid typing errors. The hash symbol ( # ) in line 1 is a special symbol in Python. It enables programmers to type comments that do not appear in the output (in the green box) when a program is executed. It s a good thing to use for typing any identifying information your instructor may require of you, like your name, course and section number, exercise number, etc. Try adding lines below line 1, starting with #, and any text you want after. Execute, and see that the text from the print statement(s) still appear in the green Terminal box, but the comments do not. Comsc 100 Page 2 of 16 Programming Exercises
Your Turn. Here s the exercise in main.py, delete the text Hello World program in Python in line 1 after the hash symbol, and type your name and student ID instead. Starting in line 2, enter additional comments as directed by your instructor. Remember to use the hash symbol at the start of each comment! Write as many comments as necessary, and leave one blank line after the last comment for spacing. Starting after the blank line that follows the comments, enter one or more print statements, printing the text that your instructor assigns. It may include your name, something about yourself, something about the class or the assignment -- however your instructor directs you. About that print statement the space before the opening parenthesis is not required. And the double-quotes can be single quotes. These are your choices pick a way and stick with it. Submitting Your Work. Your instructor may just want to see your working program in the lab, and check you off without submitting the file. Or they may require that you submit the program in printed or electronic form. In any case, you will certainly want a backup of the program you wrote, because once you close your browser, all you typed will be lost! So save it to a file: To save your work to a file, open Notepad++ or Windows 8 Notepad or Mac TextEdit (formatted to make plain text ). With that running in one window, navigate back to the browser page with main.py and select and copy the contents of the main.py box. Navigate back to Notepad or TextEdit and paste. Save it with a name as specified by your instructor. That s the file you will submit. Avoid Microsoft Word, or any rich-text editor (like Mac TextEdit formatted to make rich text ). These can lose line breaks or insert extra ones when copied back into the main.py box. If you have any further work to do on the file any more programming to do anything your instructor wants you to fix then open the file, select/copy its Python program, and paste it all into the main.py box of the browser page, and just continue from there. HINT: To clear the Terminal box, enter the comment clear: HINT: If your session expires after a long period of inactivity, select-copy your program so that you don t lose it, and use your browser s back button to restart another session. Paste your program into the main.py box, and you ll be back on track. Comsc 100 Page 3 of 16 Programming Exercises
EXERCISE 2: Using Variables And Code Blocks In Programming Purpose. The purpose of this exercise is to introduce the concept of variables, which are capable of storing and recalling data, like the memory register on a calculator. Background. The comments and the output-producing print statements are separate blocks of code called code blocks. They are separated with a blank line, although that is just cosmetic. For this exercise, we ll introduce another code block. It comes between the comments code block and the output code block. It s the variables code block. Here s a sample code block: Like the print statements, these statements have to be fully left-justified. Each line creates a variable and stores an item of data in that variable. The sample above creates two separate variables. The word to the left of the equals sign is the variable name. The text inside the single quotes is what gets stored in the variable. Referring to it by its name, as in this sample, retrieves and substitutes a variable s content. Just a few rules variable names cannot have spaces in them, or any other punctuation (except underscore). They can only consist of letters and digits (and underscores) but cannot begin with a digit. The content of the single quoted text can be anything, as long as it s all on one line anything but a single quote! So Python allows either single or double quotes for text so we can do this: Print statements can output more than just one thing. Just list them, separated by commas, like this: By referring to a variable by its name, you get a copy of its contents. Mix and match text (offset by single or double quotes) and variables, as many as you want, separated by commas. Step-By-Step. The best way to build a program with variables is to start with just one variable. Then work that variable into your output code block. If that works, add another variable, and continue oneat-a-time until you get the hang of this. So if you intend to have variables for your first and last names, create one for your first name only and make that work. Only then, proceed to your last name. This is what we call an organic approach to programming because it grows a larger program a little at a time. Learn this approach in this exercise and apply it in all the rest of these exercises. Your Turn. Here s the exercise: use your exercise 1 file as a starting place. Following the step-bystep approach, build a variables code block with variables for your first name, last name, and any additional variables specified by your instructor. Name the variables as you wish, or as instructed. Then wherever the text from any of these variables appears among the print statements, edit those print statements so that they use the variables in place of the text. That is, if your first name is Ishmael, and it s stored in a variable named first, and the word Ishmael appears in a print statement like this: print('call me Ishmael'), then write this instead: print('call me', first). Don t worry about spacing Python handles that. Submitting Your Work. Submit your work as you did in exercise 1, following any additional requirements that your instructor may specify. Comsc 100 Page 4 of 16 Programming Exercises
Samples. Here are some samples that show how to organize the three code blocks comments, variables, and output: And here s what a typing error looks like note that the variable name for the car s year is spelled differently in the variables block that it is in the output block. Python blames the error on the second spelling. Note that Python explains the error and even says the line number containing the error. Comsc 100 Page 5 of 16 Programming Exercises
EXERCISE 3: Writing An Interactive Program That Reads An Input File Purpose. The purpose of this exercise is to introduce the concept of input, in which a user of your program types text into a separate box, and the contents of the box gets copied into variables when your program executes. This one adds an input.txt box, which you ll do in several of the remaining exercises in this sequence. This kind of program is called interactive because its input is supplied by a user, and not by the programmer (you). By contrast, the input you typed in exercise 2 is called hard-wired it was typed by the programmer (you), directly into the program. Preparation. You ll need an input.txt box. Click the plus symbol next to New Project. This adds a new file named Newfile.py. Right-click Newfile.py and choose Rename File from the popup menu. Retype the name as input.txt and press ENTER: Now you should see a tab named input.txt, and you can use the tabs to navigate between the program s file, main.py, and the input file, input.txt : Use these steps for any later exercise that requires an input file. Background. Just read -- your turn's coming! You learned in exercise 2 how to create a variable and store text in it. You also learned how to retrieve a copy of that text from the variable. But you have to edit the program every time you want to change any of the values you stored in the variables. It would be nice if you could type those values into a separate input file, and get your program to pull them from there. Then you can use the same program, without modification, with any set of inputs. Here s how it s done. As the first line in the variables code block, open the input file (named input.txt to match the added tab) and come up with a variable name to represent that file in the program. (Yes, variables can be for things other than text, as we ll see in later exercises). Comsc 100 Page 6 of 16 Programming Exercises
To get the first line (line 1) from the input.txt box and store it in the variable myfirstname as text, write this: str(fin.readline().strip()). Let s take that apart. fin.readline() copies the whole first line of the input file (represented as fin), including the ENTER key that was pressed when it got typed in the input file. Adding.strip() strips out the ENTER key. str( ) interprets it as text (or as Python calls it, a string ). That s a lot to take in, so just remember that str(fin.readline().strip()) copies a line from the input file as text. (Eventually we ll find out about another option besides str.) If you use fin.readline() more than once, it skips to the next lines of the input file, one at a time. The first time it s used, it gets line 1. The second time, line 2, and so on. But there s just one fin =. Your Turn. Now it's your turn! The application for this exercise is to write a program that produces a form letter, informing a raffle winner of their prize. There are two variables (the winner s name and the raffle prize). All the rest of the text in the print statements is boilerplate that is, it s the same text for all prize winners. Develop this program organically, step-by-step. Remember that in the organic approach, the program starts from very simple beginnings usually a copy/paste/markup of a previous working program. Then add features one-by-one, testing and confirming each change. Here are the steps to write the program for this exercise, using this technique. In this case, start with the default program that you get when you first open the tutorialspoint.com web page one without a variables code block yet. Step 1, write a full form letter without any variables, to print something like this: print('congratulations, Pat Student! You won our weekly computer science department raffle. Your prize is a live six-foot python. Please collect your prize at the division office before the end of the week'). Write that like you wrote exercise 2, and make sure it all works. Then apply one or both of the following options. Option 1. Break the long wrapping print statement up into multiple, shorter statements, because you really should avoid line-wrap in programming. Even though your code may wrap in main.py and so remain legible there, it won t wrap in the Terminal box, requiring left-right scrolling in order to read it. Option 2. Keep the long, wrapping print statement, and just insert \n into the text in chosen places to force a line break. That's a backslash "en", like this: print('congratulations!\nyou win'). Line breaks force the computer to skip to a new line before printing more output. Step 2, add an input.txt window, put in it the winner s name on line 1 and the prize on line 2. Step 3, back in main.py, write a variables code block to read the name and prize from the input file. To make sure it works, put simple print statements at the end of the variables code block to print the two variables. If they are right, remove those print statements they were only to confirm things are working so far. Comsc 100 Page 7 of 16 Programming Exercises
Step 4, replace the winner s name wherever it appears in the print statements. Replace it with the variable that stores the copy of the winner s name as read from the input file. Something like print('congratulations,', winner, 'You '). Make sure it works. Step 5, replace the prize wherever it appears in the print statements, as you did the winner. If you did this right, you should be able to change the winner and prize in the input.txt box and execute the program again without modifying main.py, and see output personalized to for the winner. This is how form letters and sheets of address labels get made! Submitting Your Work. Submit your work as you did in previous exercises, submitting only the contents of main.py not input.txt. Your instructor should be able to test your program with any set of input values for winner and prize that they wish. Here s a sample: HINT: If you click the x in the main.py or the input.txt tab and lose the tab, don t worry! Just doubleclick the name of the missing tab under the symbol, and the tab will reappear, with anything you may have typed into it. HINT: Avoid typing a variable s name more than once. Copy/paste it instead. This avoids misspellings which lead to incorrect results or execution errors. HINT: Case matters in programming. Input.txt with an uppercase I is not the same as input.txt with a lowercase i. Think of the alphabet as having 52 distinct characters a-z and A-Z instead of the usual 26. Comsc 100 Page 8 of 16 Programming Exercises
EXERCISE 4: Doing Text Concatenation Purpose. The purpose of this exercise is to show how text stored in variables can be concatenated, or joined, to form new text sequences. It allows you to control spacing! This introduces a new code block that comes between the variables code block and the output code block. It s the calculations code block. It creates additional variables, but their values are not hardcoded, and not interactive (from an input file). They are calculated based on values stored in other variables. Background. Here s how to concatenate variables containing text. Presuming that the variables myfirstname and mylastname already exist, we can create new variables like this: Then you can simply print one of these new variables, like this: print(myname). Note that concatenation does not include spacing like the print statements with multiple, commaseparated values does. So the programmer has to put these in, like the text with one spacebar character separating first and last name above, and the space after Ms. above. Your Turn. Rewrite the program from exercise 3 so that there are no print statements with multiple, comma-separated values. Create concatenated variables in a calculations code block to combine into new variables what s in each of exercise 3 s print statements. Even if a print statement has just one text value (like print('congratulations!')), store that is a variable in the calculations code block. Each print statement should print a variable, only. Don t get the idea that print statements should always print just variables, and that text should always be concatenated for later printing that s not the case at all. We re just doing so here in order to show how concatenation works. Submitting Your Work. Submit your work as you did in previous exercises, submitting only the contents of main.py not input.txt. Your instructor should be able to test your program with any set of input values for winner and prize that they wish. Here s a sample of main.py and the output box: Comsc 100 Page 9 of 16 Programming Exercises
EXERCISE 5: Doing The Math Purpose. The purpose of this exercise is to show the difference between two types of data text and numbers, and how math computations can be performed with numbers. It also demonstrates how comments can be placed anywhere not just in the comment block. See the sample below. Background. In all previous exercises, the input read from the input.txt box got read as text. That s what the str( ) is doing in the variables code blocks. Even if the text involves digits and is intended as a number, it is still just text. That is, the computer does not distinguish between letters and numbers on the keyboard it s all just series of keystrokes. Remember adding the first and last names in the previous assignment? Adding 1 and 1 in the same way would result in 11. Try this: To specify that a variable should store a number, do something like this, with float instead of str: float is an abbreviation for floating point number. The floating point is the decimal in numbers that have a fractional part like 1½ is 1.5, and the period in 1.5 is the floating point. Your Turn. Write a program that converts a temperature (on line 1 of the input.txt box) from degrees Centigrade to degrees Fahrenheit. The calculation is f = 9 * c / 5 + 32, where c is the temperature in degrees C (the input), and f is degrees F (the output). You recognize the plus sign, but what are these others the slash and the asterisk? / is for division; * is multiplication. This multiplies 9 times degrees C, divides that result by 5, and then adds 32. Your output should look like this: 100.0 degrees C equals 212.0 degrees F. It should echo the value read from input.txt (in this case, 100.0) and print the calculated variable (here, 212.0), with nice labeling to identify each. Check your work by comparing these easy reference points: -40C is -40F (the only point where C and F are the same), 0C is 32F (the freezing point of water), and 100C is 212F (the boiling point of water). Submitting Your Work. Submit your work as you did in previous exercises, submitting only the contents of main.py not input.txt. Your instructor should be able to test your program with any input value for degrees C that they wish. Comsc 100 Page 10 of 16 Programming Exercises
EXERCISE 6: Statistics Calculations Finding An Average Purpose. The purpose of this exercise is to provide more practice in writing programs that (1) read numbers from an input file, (2) perform calculations, and (3) show output results. Background. You know how to read multiple values from an input file. You know how to store them as numbers. You know how to addition, multiplication, and division. And you know how to echo input values and print calculated results. That s all you need to know in order to do this exercise. Your Turn. Write a program that reads five numbers from the input.txt box s lines 1-5, adds them to get their total, and calculates their average by dividing their total by 5. For these numbers, use the present temperatures from 5 different cities in the world degrees C or F your choice. The output should something like this: But wait let s do something about all those zeros! Here s how to round off a number to a maximum of two decimal digits, using a variable name average for storing the calculated average: Statements like this belong in the calculations code block, after the variable average gets calculated and before average gets used in the output code block, like this: This is the first time we re seeing a calculation that has the same variable name appearing twice. In this case, the original number stored in average (in this case, 73.96000000000001) gets replaced with an updated, rounded-off value (in this case, it should be 73.96). Apply this, so that your program shows something like this: I rounded the total to 2 decimal digits so why do I only get.8? It s because Python rounded it to a maximum of 2 digits. In this case it got.80, and it dropped the trailing zero. It drops all trailing zeros after the first one. Submitting Your Work. Submit your work as you did in previous exercises, submitting only the contents of main.py not input.txt. Your instructor should be able to test your program with any set of input values for city temperatures that they wish. Comsc 100 Page 11 of 16 Programming Exercises
EXERCISE 7: Introducing if Logic - - Programming An RPN Calculator Purpose. The purpose of this exercise is to introduce logic into your programs. We ll put a number in each of the first two lines of input.txt, and use the 3 rd line to tell the program what to do with them. Background. We ve learned about comments, variables, calculations, input files, and print statements. Fun, but it s nothing we couldn t already do in Excel. It starts to get interesting when we start using Python s if-statement. An RPN calculator uses reverse Polish notation. It s not like the calculators we use today, where we add one and one using this sequence: one, plus, one, equals. In RPN, as the earliest digital calculators used, that sequence is one, one, add. We can write a 3-line input.txt, with numbers on the first two lines, and an instruction (like add ) on the 3 rd. We know how to read and store the numbers in variables in our variables code block. We can even read the 3 rd line and store it in a variable as text remember str( )? But what then? Here s how if-statements work in Python: There s a lot of detail here, but it s not too bad once we break it down. It s located in the calculations code block. dothis is the variable name used to store the instruction on the 3 rd line of input.txt. == (double-equals) is the symbol for comparing two things to see if they are equal, in this case, what s stored in dothis and the word add. Note these details: the spelling and casing of the word if, the parentheses, and the colon at the end. It all means that if the word read from the third line of the input file is add, spelled and cased exactly like that, then do all the statements indented under the if-statement. Otherwise, skip them entirely. For the two indented statements, note these details: they are both indented the same number of spaces. (The if-statement itself is not indented at all.) Both statements create new variables, just as if they were not indented and located in the variables code block. The numeric variables have to be converted to text using str(...) so that they can be used in text concatenation. The new variable saythis gets printed later in the output code block. Your Turn. Write a program that gets a number from each of the first two lines of input.txt, and reads an instruction from the third line. The program should perform that instruction on the two numbers and output a nicely formatted version that echoes the input numbers and the result. The operations to include are: add, subtract, multiply, divide, average, min, and max. The Python symbol for subtraction is (as you might have guessed) is (hyphen or minus). The others we saw in the temperature conversion exercise: plus ( + ), multiply ( * ) and divide ( / ). Comsc 100 Page 12 of 16 Programming Exercises
Here are sample input.txt contents that your program should be able to process: Use the organic method to create this program. To do so, start with just one operation add. Make this work for add. Once it s all working, put the next operation in multiply. Then subtract, then divide, then average, then min, then max, making sure to fully test your program each time you add one. Add and multiply are straightforward. The order of the numbers on lines 1 and 2 don t matter. But subtract and divide are a bit trickier subtraction subtracts the number from line 2 from the number in line 1. Division divides the number in line 1 by the number in line 2. Order matters! Average is just the sum divided by two, but be careful! It s not a + b / 2 as you might expect! Python scans the line and does all the multiplies and divides first, and then it takes a second pass and does the adds and subtracts. The above would divide b by 2 and add a to that result! So do this in two separate statements one that gets the sum and another that gets the average, using that sum. It s just like the addition example given above, but insert a new, indented line between the other two that says result = sum / 2. Max (return the maximum) and min (return the minimum) require logic inside logic! And they involve if-statements that don t just check for equality. The symbol to compare for equality is ==. To check if a number is less than another, it s <, and greater than is > as you might have guessed. Submitting Your Work. Submit your work as you did in previous exercises, submitting only the contents of main.py not input.txt. Your instructor should be able to test your program with any set of input numbers and any operation name that they wish. Just be sure to name the operations exactly as specified here, because your instructor will be testing with those names! Comsc 100 Page 13 of 16 Programming Exercises
EXERCISE 8: Statistics And if Logic Finding The Largest And Smallest Of 5 Numbers Purpose. The purpose of this exercise is to gain more experience with logic in your programming. Background. The way a computer finds the smallest number among a set of numbers is to assume that the first number is the smallest. Then it compares that to each remaining number, one-by-one, and changes it s mind whenever it runs across a better answer. So if a computer had this 3-number sequence: 10, 20, 30, it would create a variable named minimum and set it to 10 the first number. Then it would compare minimum (10) to the second number, 20, and replace the value stored in minimum with 20. Then it would compare minimum (now 20) to the second number, 30, and replace the value stored in minimum with 30. The number stored in minimum (30) at the end of this process is the answer. We know how to create variables to store numbers, and we know how to read numbers from an input file and store them in the variables. We know how to write if-statements, but we ve only ever tested for equality in them. Now we ll learn to test for greater or lesser. It s something like this: For more than two numbers, just repeat the if-statement, updating minimum as needed. Your Turn. Write a program to input 5 airline ticket prices from the input file (in the input.txt box), each on a separate line, stored in variables named as you wish. Create two new variables to track the minimum and maximum, and set them to the first input number. Then in a series of if-statements, compare to each of the other 4 inputs and update the minimum and maximum as needed. For output, echo the 5 input prices, and say the minimum and maximum, something like this: Submitting Your Work. Submit your work as you did in previous exercises, submitting only the contents of main.py not input.txt. Your instructor should be able to test your program with any set of ticket prices that they wish. Comsc 100 Page 14 of 16 Programming Exercises
EXERCISE 9: Sorting A List Of Names In Alphabetical Order Purpose. The purpose of this exercise is to gain more experience with logic in your programming. Background. Remember from exercise #7 that the way to check if the contents of two variables are the exact same is like this: In exercise 8 we learned the way to check if two variables contents are greater or less than one another is like this: The one on the left says if secondnumber is less than minimum, and the one on the right says if secondnumber is greater than maximum. To reorder a set of variables, you ll have to swap the contents until they are in order. Here s how to compare and swap two, so that the name stored in firstname precedes that stored in secondname, alphabetically: Your Turn. Write a program to read and store 5 names from input.txt and reorder them alphabetically, and output them. To do so, follow this recipe for your calculations code block: 1. if the first name is greater than the second name, swap them. 2. if the first name is greater than the third name, swap them. 3. if the first name is greater than the fourth name, swap them. 4. if the first name is greater than the fifth name, swap them. 1. if the second name is greater than the third name, swap them. 2. if the second name is greater than the fourth name, swap them. 3. if the second name is greater than the fifth name, swap them. 1. if the third name is greater than the fourth name, swap them. 2. if the third name is greater than the fifth name, swap them. 1. if the fourth name is greater than the fifth name, swap them. Submitting Your Work. Submit your work as you did in previous exercises, submitting only the contents of main.py not input.txt. Your instructor should be able to test your program with any set of names that they wish. Comsc 100 Page 15 of 16 Programming Exercises
EXERCISE 10: Your Own Recipe Multiplier Program Purpose. In this last exercise you get to apply all that you ve learned about programming so far, to make something useful. This program adjusts the amounts of ingredients in a recipe to make a number of servings that s different from the number of servings that the recipe makes. You ll also learn another useful application of the hash symbol for comments outside of the comment block itself, to provide a detailed description of a variable in the variables code block. Background. You know how to create variables for storing numbers, but to this point we ve only ever assigned values to the variables by reading them from input.txt. These examples show how to hard-wire an ingredient for a recipe, with a variable name to identify the ingredient and its unit of measure: Note that there are no single or double quote marks around the numbers. This is what tells Python that these are numbers and not text. This allows them to be used in the math calculations it s going to take to convert the amounts for a different number of servings. But first we need to know how many servings that the original recipe makes: Note the one new thing here is the hash symbol and the comment that follows it. This is a comment that s added to the end of a non-comment statement, to allow detailed description that s hard to put into a variable s name. Next we need to know how many servings we want to make, using this recipe. We can get that as input from the input.txt box like this: Finally, here s how to convert each ingredient, and round off the result: Your Turn. Write a program to convert your favorite recipe. Use as many ingredients as you like, as long as it s at least three. In your output, say the name of the recipe, the number of servings as input from input.txt, and the full name and amount of each ingredient, like this: Submitting Your Work. Submit your work as you did in previous exercises, submitting only the contents of main.py not input.txt. Your instructor should be able to test your program with any number of servings that they wish. Comsc 100 Page 16 of 16 Programming Exercises