CSE101 – Solved

$ 20.99
Category:

Description

Instructions
For each of the following problems, create an error-free Python program.
– At the top of every file add your name and Stony Brook email address in a comment.
– Each program should be submitted in a separate Python file that follows a particular naming convention: Submit the answer for problem 1 as “Assign1Answer1.py” and for problem 2 as “Assign1Answer2.py” and so on.
– These programs should execute properly in VS Code using the setup we created in lab.
Regarding working in pairs:
– You are welcome to work with a partner on the homework assignment, but you MUST write both your names and email addresses in each file in a comment. Only one person needs to submit the homework on Blackboard.
– You are only allowed to work together with one other person – larger group submissions or collaborations (beyond high-level discussions of problems, as stated on the syllabus) are not allowed.
Programming conventions to use
Developers use different standards for programming conventions for whitespace and variable names vary based on the language and their personal taste or organization. Consistency is important. As you program more you’ll develop your own conventions, but for this class use the conventions below:
Naming:
– Choose concise but informative variable names that would be clear to someone reading it. Avoid uncommon abbreviations. For example, hourly_rate is better than hr. An alternative style is to write hourlyRate. You can use whichever option you prefer, just be consistent.
– Variables and functions should always start with a lower-case letter. For example hourlyRate and not HourlyRate.
Whitespace:
– Use blank lines (whitespace) in your program consistently to make your program more readable.

The descriptions of conventions will not be repeated in future assignments, but be sure to continue following them for the rest of the course.

Problem 1 (1 point)
1. Download the provided Assign1Answer1.py file and bring it into VS Code.
2. Fill in your info at the top of the file.
3. Follow the instructions below and complete the program:
The basal metabolic rate (BMR) is the amount of energy (in kcal/day) expended by a person at rest in a temperate climate. The BMR is given by the following formula:
𝐵𝑀𝑅=10𝑚+6.25ℎ−5𝑎+𝑠
where 𝑚 is the person’s mass in kilograms, ℎ is the person’s height in centimeters, 𝑎 is the person’s age in years, and 𝑠 is 5 for a man and -161 for a woman.
Your program will take a person’s weight in pounds, height in total inches, and age in years. Convert these values as needed (1 lb is 0.453592 kg, 1 inch is 2.54 cm) and then print the BMR for both a man and a woman with those physical characteristics. Assume that the weight is given in a variable named weight, the height in a variable named height, and the age in a variable named age as shown in the provided code. Do not write any input statements!
You will write the code that calculates and stores the BMR for a man in the variable bmrMan and for a woman in bmrWoman so that the print statements output the results properly. You can see if your calculation is correct by trying the sample inputs given in the table below – just change the values of weight, height and age in the starting code provided.
Inputs (age, height, weight) BMR for Man (output) BMR for Woman (output)
130, 66, 55 1367.4196 1201.4196
165, 68, 23 1717.9268 1551.9268
135, 60, 16 1489.8492 1323.8492

Problem 2 (1 point)
Download the provided Assign1Answer2.py file and bring it into VS Code.
Write the implementation in the provided celsiusToFahrenheit function that will take the celsius input parameter and convert the value into Fahrenheit. Use the following formula to make the conversion:
𝐹
Problem 3 (1 point)
Go through the following steps:
1. Download the provided Assign1Answer3.py file and bring it into VS Code.
2. Fill in your info at the top of the file.
3. Run it in VS Code to make sure it works. Try to understand how all the code works.
4. Add a new function below printSum. This new function should print the information described below while satisfying the following requirements:
a. Print your name with quotation marks around it (e.g. “Alice Park”)
b. On the next line, indent the line with a tab character and then print your major and what year you started at SUNY Korea.

So when printed it will look like:

“Alice Park”

5. Add code that calls your new function and test to make sure it works without any errors.

Problem 4 (2 points)
Download the provided Assign1Answer4.py file and bring it into VS Code.
Complete the function fillPool, which computes and returns how many minutes it will take to completely fill a swimming pool of given dimensions. Suppose we have a rectangular pool with a length of length meters, width of width meters, and uniform depth of depth meters. Water is flowing into the pool at a rate of gpm gallons per minute. The function returns the time in minutes to fill the pool. Note that you will need to look up some conversion factors to figure out the solution!

Expected Results. Note that your answers might be a little different in the digits to the right of the decimal point. That is OK.
Function Call Return Value
fillPool(10, 10, 10, 1000) 264.172
fillPool(12, 13, 20, 3000) 274.739
fillPool(10, 40, 8, 250)
3381.402
Problem 5 (2 points)
For the questions below, copy the questions into a text file and write your answers below each question. Use a text editor like Notepad (Windows) or TextEdit (Mac) and save the file with a .txt or .rtf file extension.
A. What is the result of this expression: “z” * 8
B. What is a variable?
C. Assuming you have run the Python code: name = “Alice Park”
1. What does name[1] return?
2. What does name[-2] return?
3. What does name[1:-2] return?
4. What would you type to get the length of the name variable? D. What are escape sequences in Python?
E. What is the difference between an integer and floating-point number?
F. What is the result when you run the code 10 / 4 and 10 // 4 in Python? Why are they different?
G. What is the result of 6 ** 3?
H. Given (x = 1), what will be the value of x after we run (x += 3)?
I. How can we round a number in Python?
J. What is the result of float(1)?
K. What is the result of 10 == “10”?
L. What is the result of “carrot” > “banana”?

Reviews

There are no reviews yet.

Be the first to review “CSE101 – Solved”

Your email address will not be published. Required fields are marked *