Subject Computer Science Python Programming

Question

1.Define a function named printMolecularWeight( nH, nC, nO ) which returns the weight of a molecule that consists of multiple atoms of Hydrogen (H), Carbon (C) and Oxygen (O). The number of atoms of H, C and O are given by the input parameters nH, nC and nO. Additionally, some chemistry knowledge tells us that single atom of Hydrogen weighs 1, a single atom of Carbon weighs 12 and a single atom of Oxygen weighs 16. For example the call printMolecularWeight( 2, 0, 1 ) should return 18 and the call printMolecularWeight( 1, 1, 3 ) should return 61.

2.Define a function named textFileAnalysis( filename ) which prints the following information about the words within a file - number of words that have length no more than 3, number of words of length between 4 and 7, number of words with length greater than 7. The name of the file is provided as input to the function through filename. For example if the file test.txt has the famous line "Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal." inside it, then textFileAnalysis('test.txt') should print "The input file has 13 words that have length no more than three, 13 words of length between four and seven and 4 words with length greater than seven".

3.Define a function named netProfitOrLoss( transactionList ) which prints the net profit or loss from a series of financial transactions. Each transaction can be either negative (which means it is a loss) or positive (which means it was a profit). The transactionList is a list of numbers given as input to the function. For example netProfitOrLoss( [10, -110, 75, -20, 40] ) should print "There was a net loss of $5". Another example: netProfitOrLoss( [33, 800, -300, 900, -1000, 650] ) should print "There was a net profit of $1083".

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

# Q1
def printMolecularWeight(nH, nC, nO):
    return nH+12*nC+16*nO...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Assisting Tutor

Related Homework Solutions

Data Collection Script Using Python
Homework Solution
$63.00
Computer Science
Programming
Python
Windows
DOS Shell Command
Scripts
Data Collection
Algorithms
Statements
Variables
Methods
SSID
MAC Address
Signal Strength
Information
Tables
Databases
Word Counter
Homework Solution
$35.00
Computer
Science
Python
Programming
Word
Counter
Frequency
Usage
Rot13 Function
Homework Solution
$45.00
Computer
Science
Python
Programming
Rot 13
Function
Encoding
Rotation
Letters
Python Questions
Homework Solution
$48.00
Computer
Science
Python
Programming
Car
Elementary
Student
Arithmetic
Addition
Name
Age
Get help from a qualified tutor
Live Chats