Question

Complete the following function in python based on the cutomers request. Function: def hydrocarbon(hydrogen,carbon,oxygen): #Add your...

Complete the following function in python based on the cutomers request.

Function:

def hydrocarbon(hydrogen,carbon,oxygen):

#Add your code here

Customer Request:

take in three parameters assumed to be hydrogen, carbon, and oxygen IN THAT ORDER.

validate that all three values are non-negative integers:

if not than you should return None

if all three parameters are valid then you should calculate the mass of the hydrocarbon and return the mass where:

Each hydrogen has a molecular weight of 1.0079

Each carbon has a molecular weight of 12.011

Each oxygen has a molecular weight of 15.9994

For example:

hydrocarbon(4,3,0) will return 40.0646

hydrocarbon(1,2,3) will return 73.0281

hydrocarbon(-1,-1,-1) will return None

0 0
Add a comment Improve this question Transcribed image text
Answer #1

def hydrocarbon(hydrogen,carbon,oxygen):
if hydrogen < 0 or carbon < 0 or oxygen < 0:
return None
else:
return hydrogen * 1.0079 + carbon * 12.011 + oxygen * 15.9994
  

print(hydrocarbon(4,3,0))
print(hydrocarbon(1,2,3))
print(hydrocarbon(-1 , -1, -1))

Output:

$python3 main.py
40.0646
73.0281
None

ef hydrocarbon(hydrogen, carbon, oxygen): if hydrogeneor carbon<e or oxygen: python3 main.py 18.0646 73.0281 None return None

Add a comment
Know the answer?
Add Answer to:
Complete the following function in python based on the cutomers request. Function: def hydrocarbon(hydrogen,carbon,oxygen): #Add your...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 5. (12 pts) A compound contains only carbon, hydrogen, and oxygen. If complete combustion of 70.86...

    5. (12 pts) A compound contains only carbon, hydrogen, and oxygen. If complete combustion of 70.86 g of this compound produces 103.9 g of CO2 and 42.52 g of H20, what is the molecular formula of this compound if it has a molar mass of 120.104 g/mol? (Carry each step to 3 digits after the decimal)

  • Create a python add the following functions below to the module. Each section below is a...

    Create a python add the following functions below to the module. Each section below is a function that you must implement, make sure the function's names and parameters match the documentation (Copy-Paste). DO NOT put the functions in an if-name-main block. 1. def productSum(x: int, y: int, z: int) -> int This function should return: The product of x and y, if the product of x and y is less than z. Else it should return the sum of x...

  • PYTHON The provided code in the ATM program is incomplete. Complete the run method of the...

    PYTHON The provided code in the ATM program is incomplete. Complete the run method of the ATM class. The program should display a message that the police will be called after a user has had three successive failures. The program should also shut down the bank when this happens. [comment]: <> (The ATM program allows a user an indefinite number of attempts to log in. Fix the program so that it displays a message that the police will be called...

  • Solve the code below: CODE: """ Code for handling sessions in our web application """ from bottle import request, response import uuid import json import model import dbsche...

    Solve the code below: CODE: """ Code for handling sessions in our web application """ from bottle import request, response import uuid import json import model import dbschema COOKIE_NAME = 'session' def get_or_create_session(db): """Get the current sessionid either from a cookie in the current request or by creating a new session if none are present. If a new session is created, a cookie is set in the response. Returns the session key (string) """ def add_to_cart(db, itemid, quantity): """Add an...

  • python 2..fundamentals of python 1.Package Newton’s method for approximating square roots (Case Study 3.6) in a...

    python 2..fundamentals of python 1.Package Newton’s method for approximating square roots (Case Study 3.6) in a function named newton. This function expects the input number as an argument and returns the estimate of its square root. The script should also include a main function that allows the user to compute square roots of inputs until she presses the enter/return key. 2.Convert Newton’s method for approximating square roots in Project 1 to a recursive function named newton. (Hint: The estimate of...

  • + Run C Code IMPORTANT: • Run the following code cell to create the input file,...

    + Run C Code IMPORTANT: • Run the following code cell to create the input file, biostats.csv, which you will be using later. 74, In [ ]: N %%file biostats.csv Name, Sex, Age, Alex, M, 41, Bert, M, 42, Dave, M, 39, Elly, F, 30, Fran, F, 33, Jake, M, F, Luke, M, 34, F Myra, M, M, 38, Ruth, F, 28, 22 22 323 47 47, Height, Weight 170 200 167 70 115 143 139 280 98 75, 350...

  • Coding for Python - The pattern detection problem – part 3: def pattern_search_max(data_series, pattern, threshold) Plea...

    Coding for Python - The pattern detection problem – part 3: def pattern_search_max(data_series, pattern, threshold) Please do not use 'print' or 'input' statements. Context of the assignment is: In this assignment, your goal is to write a Python program to determine whether a given pattern appears in a data series, and if so, where it is located in the data series. Please see attachments below: We need to consider the following cases: Case 1 - It is possible that the...

  • You will create a PYTHON program for Tic-Tac-Toe game. Tic-Tac-Toe is normally played with two people....

    You will create a PYTHON program for Tic-Tac-Toe game. Tic-Tac-Toe is normally played with two people. One player is X and the other player is O. Players take turns placing their X or O. If a player gets three of his/her marks on the board in a row, column, or diagonal, he/she wins. When the board fills up with neither player winning, the game ends in a draw 1) Player 1 VS Player 2: Two players are playing the game...

  • Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The...

    Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The computer must select a word at random from the list of avail- able words that was provided in words.txt. The functions for loading the word list and selecting a random word have already been provided for you in ps3 hangman.py. 2. The game must be interactive; the flow of the game should go as follows: • At the start of the game, let the...

  • please use python and provide run result, thank you! click on pic to make it bigger...

    please use python and provide run result, thank you! click on pic to make it bigger For this assignment you will have to investigate the use of the Python random library's random generator function, random.randrange(stop), randrange produces a random integer in the range of 0 to stop-1. You will need to import random at the top of your program. You can find this in the text or using the online resources given in the lectures A Slot Machine Simulation Understand...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT