Question
can someone please help me write a python code for this urgently, asap

Question: Write a Python function, minmp, that is passed a file name and a metal alloys formula unit structure*. The file w
Sample Input and Output >>>isinstance (mol form (C2H601), dict) True >>isinstance (molform (C2H6), dict) True >>isinstanc
def minmp(filen ame, compound_formula ) : (str, str) When passed a filename with a listing of elements and properties and a
# This file lists several elements by symbol and their melting point # in Kelvin and density in grams per cubic centimeter. #
Question: Write a Python function, minmp, that is passed a file name and a metal alloy's formula unit structure*". The file will contain metal elements and their properties. The function will return a tuple of the element from the formula with the lowest melting point and that melting point Write a second function, molform, that will be called by the first function, to take the metal alloy's formula and return it as a database with the elements as the keys and the number of atoms as the values You may assume the compound structure will specify the number of atoms, even if the IUPAC formula would omit the subscript 1. For instance, ethanol, CaH&O, would be passed to the program as the string "C2H601". Your function must read files with the format of elements.txt. Each new column of data is separated by a tab. You can test your function using the file elements.txt. Testcases to understand the inputs and outputs of each function can be found on the next page
Sample Input and Output >>>isinstance (mol form ("C2H601"), dict) True >>isinstance (molform ("C2H6"), dict) True >>isinstance (molform ("C2 "), dict) True >>>molform ("C2H601") ('C' 2, 'O': 1) H': 6, >>molform ("C1H4") 'C' 1, H': 4 >>isinstance (minmp ("elements. txt", "Kl Fe 4 "), tuple) True >>>isinstance (minmp ("elements.txt", "K1Fe4") [0], str) True >>isinstance (minmp ("elements.txt", "Kl Fe 4") [1], int) True >>>minmp ("elements.txt", "K1Fe4 " ) ('K', 336) "Fe8Cr1 " ) >>>minmp ("elements.txt", ('Fe', 1811)
def minmp(filen ame, compound_formula ) : ""(str, str) When passed a filename with a listing of elements and properties and a compound_formula. Returns a tuple where the first element is the lowest melting point element in the compound and the second element is it's corresponding melting point >minmp("elements.txt", "K1Fe4") "К', 336 >>minmp ("elements.txt", "Fe6Cr1") 'Fe', 1811 (str, int) -> иии def molform(compound_formula) "(str) -> dictionary When passed a string of the compound formula, returns a dictionary with a string of the element symbol as the key and the number of atoms of that element as the value molform ( "C2H601") {'C':2, 'Hi:6, 'o':1} >>molfor("C1H4") {'C':1, H':4
# This file lists several elements by symbol and their melting point # in Kelvin and density in grams per cubic centimeter. # Source https://en.wikipedia.org/wiki/Chemical_element Element Melt. Pt. Density 336 0.862 K 1115 1.55 Ca 1814 2.985 Sc Ti 1941 4.506 2183 2180 1519 1811 6.0 V 7.19 Cr 7.21 Mn 7.874 Fe 1768 8.90 Co Ni 8.908 1728 1357 8.96 Cu 692 Zn 7.14 END
0 0
Add a comment Improve this question Transcribed image text
Answer #1
def molform(formula):
    """
    :param formula: string
    :return: return dict of element as key and atom as value
    """
    mol, atom = [], []
    x, y = '', ''
    for i in formula:
        # if it is element
        if i.isalpha():
            if y:
                atom.append(int(y))
                y = ''
            x += i
            continue
        # if it is number of atom
        if i.isdigit():
            if x:
                mol.append(x)
            x = ''
            y += i
            continue
    if y:
        atom.append(int(y))
    # returning dictionary
    return dict(zip(mol, atom))


def minmp(filename, formula):
    """
    :param filename: 
    :param formula: 
    :return: tuple of min melting point and element as tuple
    """
    with open(filename) as f:
        f.readline()  # reading the header
        d = {}
        for line in f.readlines():
            line = line.split('\t')
            if len(line) > 2:
                # storing the element and melting point in dict
                d[line[0]] = line[1]
        # calling above function for segarating the element
        mol_atom = molform(formula)
        min_temp = max(d.values())
        min_atom = ''
        # finding the min temp
        for x in mol_atom:
            if x in d:
                temp = d[x]
                if temp < min_temp:
                    min_temp = temp
                    min_atom = x
        return min_atom, min_temp

# OUTPUT

Add a comment
Know the answer?
Add Answer to:
can someone please help me write a python code for this urgently, asap Question: Write a Python function, minmp,...
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
  • Python Code help needed. Based on the file (2nd picture) a dictionary like the third picture...

    Python Code help needed. Based on the file (2nd picture) a dictionary like the third picture is to be made. def load_locations(filename): (str) -> dict Read data from the file with the given fi lename and create and return a dictionary with location data, structured as descr ibed in the ass ignment handout, Part 1 Section I1 [BEGIN DESCRIPTION There is nothing interesting here [END DESCRIPTION] BEGIN DESCRIPTION] You wake up lost in some unfamiliar place. All you know is...

  • Hey guys I need help with this question with 3 sub-problems. f test remove short synonyms () Define the remove shorti s...

    Hey guys I need help with this question with 3 sub-problems. f test remove short synonyms () Define the remove shorti synonyms function which is passed a dictionary as a parameter- The keys of the parameter dictionary are words and the corresponding values are 1ists of synonyms (synonyms are words which have the same or nearly the same meaning). The function romoves all the eynonyme which have ous than 8 charactors from each corresponding list of synonyms-As well, the funet...

  • C++ programming question Topic: Class 'Date' Hello everybody, can some one help me... ... Write a...

    C++ programming question Topic: Class 'Date' Hello everybody, can some one help me... ... Write a class Date with the following properties: a) Data elements of the class are day, month, year. All three data elements are defined by the Type int. b) A set and a get element function are to be provided for each data element. In Within the framework of this task, it should be assumed that the values that are passed for day and year, are...

  • Hello can anyone help solve this please in Python the way it's asked? Question 22 40 pts List Comprehensions Write...

    Hello can anyone help solve this please in Python the way it's asked? Question 22 40 pts List Comprehensions Write the solution to a file named p2.py and upload it here. Comprehensions will show up at the midterm exam, so it's important to practice. a) Write a list comprehension that returns a list [0, 1,4, 9, 16, .. 625] starting from range(0, 26). (lots of list elements were omitted in ...) b) Write a list comprehension that returns the list...

  • I need a python 3 help. Please help me with this question Part 2. Linked Lists...

    I need a python 3 help. Please help me with this question Part 2. Linked Lists You start working with the class LinkNode that represents a single node of a linked list. It has two instance attributes: value and next. class LinkNode: def __init__(self,value,nxt=None): assert isinstance(nxt, LinkNode) or nxt is None self.value = value self.next = nxt Before you start with the coding questions, answer the following questions about the constructor Valid Constructor or Not? LinkNode(1, 3) LinkNode(1, None) LinkNode(1,...

  • Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is...

    Using Python, if you could help me with the code # Create a modified version of the search linear function defined # above to return all # occurrences of the search word in the text # An occurrence is the index of a word in the text that matches your given # search string. # e.g. if "hatter" occurs at positions 0, 6, 12 then return [ 0, 6, 12] def search_linear_occurrences(xs, target): """ Find and return a list of...

  • PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please...

    PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList:     def __init__(self):         self.__head = None         self.__tail = None         self.__size = 0     def insert(self, i, data):         if self.isEmpty():             self.__head = listNode(data)             self.__tail = self.__head         elif i <= 0:             self.__head = listNode(data, self.__head)         elif i >= self.__size:             self.__tail.setNext(listNode(data))             self.__tail = self.__tail.getNext()         else:             current = self.__getIthNode(i - 1)             current.setNext(listNode(data,...

  • PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment...

    PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...

  • urgent help with python. can somone code this please and show output QUESTION: There are a variety of games possi...

    urgent help with python. can somone code this please and show output QUESTION: There are a variety of games possible with a deck of cards. A deck of cards has four different suits, i.e. spades (*), clubs (*), diamonds (), hearts (), and thirteen values for each suit. Now write a function that uses list comprehension to create a deck of cards. Each element in the list will be a card, which is represented by a list containing the suit...

  • can someone write me a wing101 python code for this please Question: For a projectile launched with a velocity vIm/s) at an angle to the horizontal 6 Iradl, the horizontal distance travelled (al...

    can someone write me a wing101 python code for this please Question: For a projectile launched with a velocity vIm/s) at an angle to the horizontal 6 Iradl, the horizontal distance travelled (also called the range) is given by where the altitude of the landing position is Δh higher than that of the launch position and g is the gravitational acceleration (use 9.81 m/s^2). Note: θ in theformula is in radians write a Python function that accepts ν, θ and...

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