$30
Department of Computer Science Introduction to Computer Science Assignment 1 Programming Basics
Total Marks: 18 General Instructions • This assignment is individual work. You may discuss questions and problems with anyone, but the work you hand in for this assignment must be your own work. • Each question indicates what to hand in. You must give your document the name we prescribe for each question, usually in the form aNqM, meaning Assignment N, Question M. • Make sure your name and student number appear at the top of every document you hand in. These conventions assist the markers in their work. Failure to follow these conventions will result in needless effort by the markers, and a deduction of grades for you. • Do not submit folders, or zip files, even if you think it will help. It might help you, but it adds an extra step for the markers. • Programs must be written in Python 3.5+. • Assignments must be submitted to Canvas. There is a link on the course webpage that shows you how to do this. • Canvas will not let you submit work after the assignment deadline. It is advisable to hand in each answer that you are happy with as you go. You can always revise and resubmit as many times as you like before the deadline; only your most recent submission will be graded. • Read the purpose of each question. Read the Evaluation section of each question. Department of Computer Science 176 Thorvaldson Building 110 Science Place, Saskatoon, SK, S7N 5C9, Canada Telephone: (306) 966-4886, Facsimile: (306) 966-4884 CMPT 141 Winter 2024 Introduction to Computer Science Question 1 (6 points): Purpose: To familiarize you with the Academic Honesty policy, and Canvas’s assignment submission, and to do a little writing practice. Read the Academic Honesty page at https://www.cs.usask.ca/students/current-students/academic-honesty. php (click coloured text to open). In the context of what you read, which of the following scenarios are violations of academic honesty? Explain in one or two sentences why or why not by referring to the academic honesty webpage. Please do not write lengthy answers. (a) Red and Blue are working on an assignment together. Red emails her answer to Blue. Blue copies it and hands it in. (b) Giovanni and Ash are enemies. Ash hacks into Giovanni’s user account, and copies Giovanni’s work for the assignment. (c) Squirtle, Charry, Bulba, and Pikachu are a study group who have decided to work together on the assignment. Each of them answered one question, and then brought the answer to the group for discussion. After a long process of discussion and analysis, in which all the group members participated equally, they created a final answer to each question that they all copied. (d) Brock and Misty just met in the lab. Misty has done some programming before, but Brock is a novice. Misty helped Brock fix his program so that it looked pretty much like her own. (e) Jessie and James were passing through the lab when their friend Meowth stopped them and asked them for help figuring out why his program wasn’t working right. James and Jessie looked at Meowth’s program and explained what the problem was and what was causing it. Meowth thanked them (grouchily), and proceeded to fix the error on his own. (f) Mewtwo and Lucario worked on the assignment together. Once they were fairly sure they understood the solutions, they destroyed all copies of their work. After playing an hour of Pokemon, they recreated the solutions to the assignment separately, from scratch, without consulting each other, or the notes they made. Feel free to discuss these scenarios with other students, TAs, and instructors. It’s very important that everyone understand the rules, as they will be applied to all assignments in this course. When the solutions are released, come back to these scenarios to make sure your understanding is consistent with ours! What to Hand In Hand in your answers in a file called a1q1. Allowed file formats are plain text (.txt), Rich Text (.rtf), and PDF (.pdf). We permit only these formats to ensure that our markers can open your files. Documents that cannot be opened conveniently will not be graded and receive 0 points. Evaluation • 1 mark for each correct answer. Answers should be justified by referring to the academic honesty policy. Writing style need not be formal, but should reflect an attempt at university-level English. • -1 mark if identifying information is missing (name, NSID, student number and instructor’s name). We are not grading for grammar or spelling. These are important, but there are other classes to evaluate that. However, there should be an attempt to make complete sentences, and students should avoid unprofessional abbreviations. Answers that cannot be understood because of poor writing will receive 0 marks. Page 2 Department of Computer Science 176 Thorvaldson Building 110 Science Place, Saskatoon, SK, S7N 5C9, Canada Telephone: (306) 966-4886, Facsimile: (306) 966-4884 CMPT 141 Winter 2024 Introduction to Computer Science Question 2 (5 points): Purpose: To practice console input and output of strings. A "mad-lib" is a fill-in-the blank game. One player writes a short story in which some words are replaced by blanks. For each word that is removed, the appropriate part of speech is noted: e.g. noun (person/- place/thing), adjective (word that describes a noun), verb (an action, e.g. eat), adverb (modifies a verb, e.g. quickly). Then, before reading the story, the story-writer asks the other player to write down a word of the appropriate part of speech for each blank without knowing the context in which it will be used. In this way, a humorous (sometimes) or non-sensical (usually) story is created. Write your own mad-lib. It must have at least three blanks in it. Now write a Python program that does the following: (a) Using the input() syntax (see the section "Reading Strings from the Keyboard" from the course readings) for reading strings from the console, prompt the user to enter a word of the appropriate part of speech for each blank in your program. Have a different, appropriately named variable refer to each word. (b) Print your story to the console using the print() syntax, filling in the blanks in your story using the strings referred to by the variables that you gathered in Step 1. While it is possible to do this using a single print(), readability of code is important! You are permitted to use as many print() statements as you wish. You must write your own unique story. There is no good reason why two students should submit the same story. Remember you must use a minimum of three blanks, and therefore, your program must read at least three words from the console. You can have more blanks, but get all your other work done before you spend a lot of time having fun with this question! Sample Run Here is an example of how your program’s console output might look. Do not submit this story! Write your own story. In our example, we use green text to show what the user typed in; blue text highlights where the user’s data gets put in the story. If you’re using PyCharm to run your program, the user input will also be green, but it won’t show any blue text. ✞ ☎ Enter a verb ending in " ing ": zipping Enter a noun : squirtle Enter a verb ( past tense ): zapped Pikachu was zipping through some tall grass . Suddenly , a squirtle appeared ! The squirtle zapped Pikachu . It was not very effective . ✝ ✆ What to Hand In A file called a1q2.py containing your finished program, as described above. Evaluation • 2 marks for reading text from the console; • 2 marks for printing the story to the console in an aesthetically pleasing manner; • 1 mark for choosing appropriate variable names (variable names should be descriptive of the data referred to by the variable; single-letters and abbreviations should be avoided). • -1 mark if identifying information is missing (name, NSID, student number and instructor’s name). Page 3 Department of Computer Science 176 Thorvaldson Building 110 Science Place, Saskatoon, SK, S7N 5C9, Canada Telephone: (306) 966-4886, Facsimile: (306) 966-4884 CMPT 141 Winter 2024 Introduction to Computer Science Question 3 (7 points): Purpose: To practice the use of arithmetic expressions. The notorious pirate, Tractor Jack, has spent the summer sailing up and down the Saskatchewan River, raiding silos, and stealing tons of wheat, barley and other grains. With winter coming, it’s time for Tractor Jack to divide up this booty amongst his crew. The accord Tractor Jack has with his crew is that, as captain, he receives 30% of all the booty. The rest is to be divided up amongst his crew in equal shares. Finally, Jack, being a socially responsible pirate, anonymously donates 15% of his own share of the booty to the Saskatoon Food Bank. Write a program for Tractor Jack that will ask the user to input the total value of booty plundered (in dollars), and the number of crew (not including Tractor Jack himself). Then the program should display the value of Tractor Jack’s share of the booty (before his charitable donation), the value of the remaining share to be divided amongst the crew, the value of booty that each crew member receives, and the amount of money Jack donates to the food bank. You may assume that the user supplies valid input from the console, that is, a positive number for the amount of plunder, and a positive integer for the number of crew. Sample Run If completed correctly, your program’s console output should look something like this. As usual, green text shows the text entered by the user, and blue text highlights the values calculated by the program. ✞ ☎ Enter the total value of wheat , barley and other grains plundered in dollars : 9000 Enter the number of crew : 17 Tractor Jack ' s 30% share of the booty is worth : $2700.0 Crew ' s 70% share of the booty is worth : $6300.0 Each crew member takes home : $370.5882352941176 Jack donates $405.0 to the Saskatoon Food Bank . ✝ ✆ Notice that the user is not expected to type the $ when entering the value of the wheat, barley, and all the other grains. It is also not a concern if your displayed dollar amounts have more or less than two digits after the decimal place, or don’t have a decimal at all. You will not be penalized for this (unless the values computed are incorrect). If you are having trouble getting the dollar amounts to print right next to the dollar signs without a space in between, think about how you might use the string concatenation operator (the very end of textbook Section 2.3.4 "Operators on Strings") to achieve the desired output. For more about the exciting adventures of Tractor Jack, click here. What to Hand In Hand in your solution in a file called a1q3.py. Evaluation • 1 mark for reading in the total plunder and number of crew from the console; • 4 marks for displaying the correct dollar amounts (1 mark each); • 1 mark for formatting the dollar amounts without a space between the dollar sign and the amount; • 1 mark for choosing appropriate variable names (variable names should be descriptive of the data referred to by the variable; single-letters and abbreviations should be avoided). • -1 mark if identifying information is missing (name, NSID, student number and instructor’s name). Page 4