Python Forum
Python code for counting money at multiple stores
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python code for counting money at multiple stores
#1
I need help a python code that asks what is below kind of struggling to put it together.
(You need to keep track of the amount of money that comes in from all of the stores. To accommodate this situation you decide to make a python program that will ask you the location/name of each store you manage. For each store, the program will ask that you enter in the following values: 100's, 50's, 20's, 10's 5's, 1's, quarters, dimes, nickles, and pennies, the program will take those values and add them to give the store total. The program will then take all the store totals and will calculate a grand total for all stores. Finally the program should ask the user if they want to save the information, if the user answers yes, the program should save the data to a .txt file.

Variables for the program should be named according to the data it represents. Comments need to be entered so that anyone who looks at the code can figure out what is happening. Error traps need to be used to validate data that is entered. Remember to keep the program as simple as possible, and add complexity if desired only after the core program works.

The use of pseudocode will be invaluable for working out the logic of the program.python code that is going to be rather long any help is appreciated.)
Reply
#2
What have you tried so far?  Is there something you're stuck with?  We can help you with problems, but we're not going to write the program for you.  Is this a homework assignment?
Reply
#3
(Oct-13-2020, 07:10 PM)bowlofred Wrote: What have you tried so far?  Is there something you're stuck with?  We can help you with problems, but we're not going to write the program for you.  Is this a homework assignment?
It is just something I am doing for fun. stock on getting the code for the name and location of the stores as well as asking if the user wants to save in text file that I don't know where to start.
Reply
#4
(Oct-14-2020, 12:25 AM)duddey Wrote: It is just something I am doing for fun. /../ I don't know where to start.

There are different ways to define 'fun' but for assignment where I have no idea how to start I would use totally different sequence of words.

But about task at hand. For me there is ambiguity in wording: "make a python program that will ask you the location/name of each store you manage. For each store, the program will ask that you enter in the following values: 100's, 50's, 20's, 10's 5's, 1's, quarters, dimes, nickles, and pennies". Should I ask first for names of all stores and after that quantities of notes/coins in every store or should I ask one-by-one: store name and quantities of notes/coins in this store and after that repeat it with the next store.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#5
(Oct-14-2020, 02:13 PM)perfringo Wrote:
(Oct-14-2020, 12:25 AM)duddey Wrote: It is just something I am doing for fun. /../ I don't know where to start.

There are different ways to define 'fun' but for assignment where I have no idea how to start I would use totally different sequence of words.

But about task at hand. For me there is ambiguity in wording: "make a python program that will ask you the location/name of each store you manage. For each store, the program will ask that you enter in the following values: 100's, 50's, 20's, 10's 5's, 1's, quarters, dimes, nickles, and pennies". Should I ask first for names of all stores and after that quantities of notes/coins in every store or should I ask one-by-one: store name and quantities of notes/coins in this store and after that repeat it with the next store.

Yes the program should ask for the names of the stores first and then calculate the amount of money for that store and then combine the totals of all the stores one would manage. I have no idea where to start just getting a start on the program would help.
Reply
#6
values = input("Input the names of the stores you work at : ")
list = values.split(",")
tuple = tuple(list)
print('name of stores')
int main ()
float amtDue = 0;
float amtGiven = 0;
float balAmount =0;

float twenty = 20.00
float ten = 10.00;
float five = 5.00;
float one = 1.00;
float quarter = .25;
float dime = .10;
float nickel = .05;
float penny = .01;

printf ("Enter the Amount Due: ");
scanf ("%f", &amtDue);

printf ("Enter the Amount Given: ");
scanf ("%f", &amtGiven);

balAmount = amtDue - amtGiven;

printf ("Change Due: $ %f", balAmount);
// This is where I really don't know the code but put what my best idea is something like


float modTwenty = amtbalance % twenty;
float modTen = modTwenty % ten;
// and so on down the line, I can figure out the float or int once I am behind my compiler
// I am using float because I am using MOD and want the result to be true, then using %d to printf the int so it doesn't say something like 2.3 twenties which is impossible

printf ("Twenties: %d \nTens: %d", modTwenty, modTen);

system ("pause");
return 0;
}

with open('outfile.txt', 'w') as outfile:
print >>outfile, 'Data collected on:', input['header']['timestamp'].date()

This is what I came up with but I don't think this is any where near what I need and I am getting a syntax error.
Reply
#7
You can't write javasque and expect it work in Python. You should learn Python syntax and then write valid Python code.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#8
(Oct-15-2020, 04:20 AM)perfringo Wrote: You can't write javasque and expect it work in Python. You should learn Python syntax and then write valid Python code.

OK
Reply
#9
pennies = int(input("Enter pennies:"))
nickels = int(input("Enter nickels:"))
dimes = int(input("Enter dimes:"))
quarters = int(input("Enter quarters:"))
print("You entered:")
print("\tPennies:" , pennies)
print("\tNickels:" , nickels)
print("\tDimes:" , dimes)
print("\tQuarters:" , quarters)
total_value = get_total(pennies, nickels, dimes, quarters)
v_Dollars, v_Cents = divmod(total_value, 1)
print("Total = ${:,.2f}".format(total_value))
print("You have {:,} dollar(s) and {:.2f} cent(s)".format(int(v_Dollars), v_Cents))
def get_total(pennies, nickels, dimes, quarters):
pennies = (.01 * pennies);
nickels = (.05 * nickels);
dimes = (.10 * dimes);
quarters = (.25 * quarters);
total_value = pennies + nickels + dimes + quarters
return total + value
with open('outfile.txt', 'w') as outfile:
print >>outfile, 'Data collected on:', input['header']['timestamp'].date()
I changed things around and came up with this instead.
Reply
#10
If it were my program, I would use arrays where each array element would be for a particular store.

Maybe start something like below. Then, when asking for the information, use the array index to keep things in order.

To add it all up, just do the math. To write it out, use the index.

Or, think about multi dimensional arrays!

from array import *
StoreName = array('c',[' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',])
StoreNumber = array('i',[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
Twenties    = array('i',[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
Tens        = array('i',[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
Fives       = array('i',[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
Twos        = array('i',[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
Ones        = array('i',[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
Quarters    = array('i',[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0])
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python convert multiple files to multiple lists MCL169 6 1,568 Nov-25-2023, 05:31 AM
Last Post: Iqratech
  python multiple try except block in my code -- can we shorten code mg24 10 6,178 Nov-10-2022, 12:48 PM
Last Post: DeaD_EyE
  Money conversion - problems with lists and .format function fatherted99 1 1,825 Mar-12-2020, 06:29 PM
Last Post: ndc85430
  multiple problems with code SrijaRamarthy 2 1,870 Nov-06-2019, 06:24 AM
Last Post: SrijaRamarthy
  Python code to copy data from multiple workbooks into master sheet Fatman003 2 3,820 Aug-21-2019, 11:23 AM
Last Post: Fatman003
  Running a code through multiple files in a folder Rai 1 2,501 Feb-13-2018, 12:42 PM
Last Post: Larz60+
  How many money in 30 days. miguelramos122 4 5,760 Dec-16-2017, 12:48 PM
Last Post: squenson
  What is wrong with code? Bin. Tree counting Peter_EU 3 3,453 Nov-08-2017, 08:41 AM
Last Post: heiner55
  MONEY CHANGE OmarSinno 5 5,580 Oct-21-2017, 05:51 AM
Last Post: Larz60+
  Multiple Question Results code flynnmackie 2 77,381 Mar-13-2017, 06:54 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020