Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

COMP 202 Fall 2021 Assignment 1 Due: Wednesday, October 6th, 11:59 p.m. Please read the entire PDF before starting. You must do this assignment individually. Question 1: 15 points Question 2: 85...

1 answer below »
COMP 202
Fall 2021
Assignment 1
Due: Wednesday, October 6th, 11:59 p.m.
Please read the entire PDF before starting. You must do this assignment individually.
Question 1: 15 points
Question 2: 85 points
100 points total
It is very important that you follow the directions as closely as possible. The directions, while
perhaps tedious, are designed to make it as easy as possible for the TAs to mark the assignments by letting
them run your assignment, in some cases through automated tests. While these tests will never be used
to determine your entire grade, they speed up the process significantly, allowing the TAs to provide bette
feedback and not waste time on administrative details. Plus, if the TA is in a good mood while grading,
then that increases the chance of them giving out partial marks. :)
To get full marks, you must follow all directions below:
• Make sure that all file names and function names are spelled exactly as described in this document.
Otherwise, a 50% penalty per question will be applied.
• Make sure that your code runs without e
ors. Code with e
ors will receive a very low mark.
• Write your name and student ID in a comment at the top of all .py files you hand in.
• Name your variables appropriately. The purpose of each variable should be obvious from the name.
• Comment your code. A comment every line is not needed, but there should be enough comments
to fully understand your program.
• Avoid writing repetitive code, but rather call helper functions! You are welcome to add additional
functions if you think this can increase the readability of your code.
• Lines of code should NOT require the TA to scroll horizontally to read the whole thing.
• Vertical spacing is also important when writing code. Separate each block of code (also within a
function) with an empty line.
• Up to 30% can be removed for bad indentation of your code, omission of comments,
and/or poor coding style (as discussed in class).
Hints & tips
• Start early. Programming projects always take more time than you estimate!
• Do not wait until the last minute to submit your code. Submit early and often—a good rule of
thumb is to submit every time you finish writing and testing a function.
• Write your code incrementally. Don’t try to write everything at once. That never works well. Start
off with something small and make sure that it works, then add to it gradually, making sure that it
works every step of the way.
• Read these instructions and make sure you understand them thoroughly before you start. Ask questions
if anything is unclear!
• Seek help when you get stuck! Check our discussion board first to see if your question has already
een asked and answered. Ask your question on the discussion board if it hasn’t been asked already.
Talk to your TA during office hours if you are having difficulties with programming. Go to my office
hours if you need extra help with understanding a part of the course content.
– At the same time, beware not to post anything that might give away any part of your solution—this
would constitute plagiarism, and the consequences would be unpleasant for everyone involved. If
you cannot think of a way to ask your question without giving away part of your solution, then
please drop by our office hours.
• If you come to see us in office hours, please do not ask “Here is my program. What’s wrong with it?”
We expect you to at least make an effort to start to debug your own code, a skill which you are meant
to learn as part of this course. And as you will discover for yourself, reading through someone else’s
code is a difficult process—we just don’t have the time to read through and understand even a fraction
of everyone’s code in detail.
– However, if you show us the work that you’ve done to na
ow down the problem to a specific
section of the code, why you think it doesn’t work, and what you’ve tried to fix it, it will be much
easier to provide you with the specific help you require and we will be happy to do so.
Revisions
Sept 20: Co
ected examples for find_maximal_subplots function.
Sept 21: Co
ected return value in example for calculate_cost function.
Sept 22: Adjusted phrasing for get_num_subplots_for_budget function (should read ‘spacing between sub-
plots’, not ‘spacing between plots’). Also, undid part of the change made on Sept. 20 (spacing in the example
for find_maximal_subplots is indeed 1.67m, not 2.0m).
Page 2
Part 1 (0 points): Warm-up
Do NOT submit this part, as it will not be graded. However, doing these exercises might help you to do the
second part of the assignment, which will be graded. If you have difficulties with the questions of Part 1, then
we suggest that you consult the TAs during their office hours; they can help you and work with you through
the warm-up questions. You are responsible for knowing all of the material in these questions.
Warm-up Question 1 (0 points)
Practice with Number Bases:
We usually use base 10 in our daily lives, because we have ten fingers. When operating in base 10,
numbers have a ones column, a tens column, a hundreds column, etc. These are all the powers of 10.
There is nothing special about 10 though. This can in fact be done with any number. In base 2, we
have each column representing (from right to left) 1,2,4,8,16, etc. In base 3, it would be 1,3,9,27, etc.
Answer the following short questions about number representation and counting.
1. In base 10, what is the largest digit that you can put in each column? What about base 2? Base
3? Base n?
2. Represent the number thirteen in base 5.
3. Represent the number thirteen in base 2.
4. What is the number XXXXXXXXXXin base 10?
Warm-up Question 2 (0 points)
Logic:
1. What does the following logical expression evaluate to?
(False or False) and (True and (not False))
2. Let a and b be boolean variables. Is it possible to set values for a and b to have the following
expression evaluate as False?
or (((not a) or (not a)) or (a or (not b)))
Warm-up Question 3 (0 points)
Expressions: Write a program even_and_positive.py that takes an integer as input from the user and
displays on your screen whether it is true or false that such integer is even, positive, or both.
An example of what you could see in the shell when you run the program is:
%Run even_and_positive.py
Please enter a number: -2
-2 is an even number: True
-2 is a positive number: False
-2 is a positive even number: False
%Run even_and_positive.py
Please enter a number: 7
7 is an even number: False
7 is a positive number: True
7 is a positive even number: False
Page 3
Warm-up Question 4 (0 points)
Conditional statements: Write a program hello_bye.py that takes an integer as input from the user.
If the integer is equal to 1, then the program displays Hello everyone!, otherwise it displays Bye bye!.
An example of what you could see in the shell when you run the program is:
%Run hello_bye.py
Choose a number: 0
Bye bye!
%Run hello_bye.py
Choose a number: 1
Hello everyone!
%Run hello_bye.py
Choose a number: 329
Bye bye!
Warm-up Question 5 (0 points)
Void Functions: Create a file called greetings.py, and in this file, define a function called hello. This
function should take one input argument and display a string obtained by concatenating Hello with the
input received. For instance, if you call hello("world!") in your program you should see the following
displayed on your screen:
Hello world!
• Think about three different ways of writing this function.
• What is the return value of the function?
Warm-up Question 6 (0 points)
Void Functions: Create a file called drawing_numbers.py. In this file create a function called display_two.
The function should not take any input argument and should display the following pattern:
22
2 2
2
2
22222
Use strings composed out of the space character and the character ‘2’.
• Think about two different ways of writing this function.
• Try to write a similar function display_twenty which displays the pattern ‘20’
Warm-up Question 7 (0 points)
Fruitful Functions: Write a function that takes three integers x, y, and z as input. This function
eturns True if z is equal to 3 or if z is equal to the sum of x and y, and False otherwise.
Warm-up Question 8 (0 points)
Fruitful Functions: Write a function that takes two integers x, y and a string op. This function returns
the sum of x and y if op is equal to +, the product of x and y if op is equal to *, and zero in all othe
cases.
Page 4
Part 2
The questions in this part of the assignment will be graded.
The main learning objectives for this assignment are:
• Co
ectly create and use variables.
• Learn how to build expressions containing different type of operators.
• Get familiar with string concatenation.
• Co
ectly use print to display information.
• Understand the difference between inputs to a function and inputs to a program (received from the
user through the function input).
• Co
ectly use and manipulate inputs received by the program from the function input.
• Co
ectly use simple conditional statements.
• Co
ectly define and use simple functions.
• Solidify your understanding of how executing instructions from the shell differs from running a program.
Note that this assignment is designed for you to be practicing what you have learned in the
videos up to and including Lecture 11 (Functions 3). For this reason, you are NOT allowed to
use anything seen after Lecture 11 or not seen in class at all. You will be heavily penalized if
you do so.
For full marks, in addition to the points listed on page 1, make sure to add the appropriate documentation
string (docstring) to all the functions you write. The docstring must contain the following:
• The type contract of the function.
• A description of what the function is expected to do.
• At least 3 examples of calls to the function. You are allowed to use at most one example per function
from this PDF.
Examples
For each question, we provide several examples of how your code should behave. All examples are given as
if you were to call the functions from the shell.
When you upload your code to codePost, some of these examples will be run automatically to test that
your code outputs the same as given in the example. However, it is your responsibility to make
Answered 1 days After Oct 05, 2021

Solution

Sathishkumar answered on Oct 06 2021
140 Votes
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 6 10:15:09 2021
@author:
"""
import turtle
turtle.Screen().bgcolor('black')
turtle.color("pink")
turtle.write("Jason",font=("Cali
i", 32, "bold"))
sh=input('Hello! Enter shape t-triangle or c-circle:')
cl=input('Hello! Enter color to...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here