Mo Money- Making an algorithm to solve two variable algebra problems

2024/7/8 8:39:29

A cash drawer contains 160 bills, all 10s and 50s. The total value ofthe 10s and 50s is $1,760.

How many of each type of bill are in the drawer? You can figure thisout by trial and error (or by doing algebra with pencil and paper),but try to use loops and conditionals to check a plausiblepossibilities and stop when you find the correct one.

Algebraically, on a piece of paper I figured out that it was four $50 bills and one hundred and fifty six $10 bills. This is because

  1. x+y=160

  2. 10x+50y=1760

    x=160-y

    10x=1600-10y

    1600-10y+50y=1760

    1600-40y=1760

    40y=1760

    y=4

    x=156

how would I make a model that i could code to solve this or any other version of this problem? I only know the very basic syntax of python as i've never ever programmed before this.

Answer

Using numpy for the system:

x+y=16010x+50y=1760
import numpy as np
a = np.array([[1, 1], [10, 50]])
b = np.array([160, 1760])
x = np.linalg.solve(a, b)
print(x)

Outputs:

[156.   4.]
https://en.xdnf.cn/q/120131.html

Related Q&A

How to explode Python Pandas Dataframe and merge strings from other dataframe?

Dataframe1 has a lot of rows and columns of data. One column is Text. Certain rows in Text column have strings and some strings include within the strings this {ExplodeEList2} How to explode (expand) t…

Creating a new column with numbers in Pandas to group with a column with existing numbers

Good day, I have a column from a data frame here:A231011 22My objective is to create a new column and associate the numbers like this:A file_number 23 8 10 6 11 6 22 8As…

How to get PDF file from the binary data of SoftLayers quote?

I got the binary data by "getPdf" method of SoftLayers API.Ref. BillingSoftLayer_Billing_Order_Quote::getPdf | SoftLayer Development Network - http://sldn.softlayer.com/reference/services/Sof…

How to list of elements and use those elements as a header of pandas dataframe?

I have a list with some elements. For example: list= [name, phone_number,age,gender] I want to use these elements as a header or column name in a pandas dataframe. I would really appreciate your ideas.…

Averaging Filter using python

I am new in python and trying apply averaging filter on image as the way i understand averaging concept summing up the neighboring elements including itself and divide it by number of elementstechnique…

Click on Show more deals in webpage with Selenium

Id like to click on every Show 10 more deals on the following page: "https://www.uswitch.com/broadband/compare/deals_and_offers/" but it does not seem to work. Im stuck having the following e…

In Matplotlib, what axis attribute specifies the spacing between ticks? [duplicate]

This question already has answers here:Changing the tick frequency on the x or y axis(15 answers)Closed 6 years ago.When generating a Matplotlib line or scatter plot, what axis attribute specifies the …

How can I make a simple calculator in python 3?

Im making this calculator using python 3, and this is what I have so far:print("Welcome to Calculator!")class Calculator:def addition(self,x,y):added = x + yreturn addeddef subtraction(self,x…

python 3: lists dont change their values

So I am trying to change a bunch of list items by a random percentage using a for loop.import random as rdm list = [1000, 100, 50, 25] def change():for item in list:item = item + item*rdm.uniform(-10, …

Using zip_longest on unequal lists but repeat the last entry instead of returning None

There is an existing thread about this Zipping unequal lists in python in to a list which does not drop any element from longer list being zipped But its not quite Im after. Instead of returning None, …