473,326 Members | 2,136 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

solving a small programm

hey,

for the real programmers amongst you, this may be really annoying but I've
been learning the language for only two days.

this is my problem,
in this programm,which already works I now have to make a total count of how
many coins are used.
this program gives the total per coin. It should be a small peace of code
(as explained in a tutorial i read, without the answer.)that counts the
total of all the coins.
I ve been searching for two days and for this kind of programm it really
seems kind of long.

thanks in advance

# Een bedrag gepast betalen met zo min mogelijk euromunten

bedrag = input ( 'Geef bedrag tussen 0 en 500 eurocent: ' )

for munt in 200, 100, 50, 20, 10, 5, 2, 1 :
aantal = 0

while bedrag >= munt :
aantal = aantal + 1
bedrag = bedrag - munt

if aantal > 0 :
print aantal, 'x', munt

what i need is:
for example
the programm gives
68= 50*1
10*1
5*1
2*1
1*1
I need an additional code to get the "5" total of all the coins together.


Jul 18 '05 #1
7 1507
That sounds like a homework problem, so rather than write the code for
you, here's a hint -- use another variable, and update it every time
you decide how many coins of any specific size you'll use.
Jul 18 '05 #2
djw
As this is obviously a class assignment of some sorts, I don't know how much
help you are going to get (or should get) in directly writing the code.
But, what I will say is that you should be able to look at the way the code
works now, how it keeps track of how many bills are needed for each
denomination (200, 100, etc), and apply the same idea to the total number
of bills required using another variable that is initialized before the
loop begins.

-d
broebel wrote:
hey,

for the real programmers amongst you, this may be really annoying but I've
been learning the language for only two days.

this is my problem,
in this programm,which already works I now have to make a total count of
how many coins are used.
this program gives the total per coin. It should be a small peace of code
(as explained in a tutorial i read, without the answer.)that counts the
total of all the coins.
I ve been searching for two days and for this kind of programm it really
seems kind of long.

thanks in advance

# Een bedrag gepast betalen met zo min mogelijk euromunten

bedrag = input ( 'Geef bedrag tussen 0 en 500 eurocent: ' )

for munt in 200, 100, 50, 20, 10, 5, 2, 1 :
aantal = 0

while bedrag >= munt :
aantal = aantal + 1
bedrag = bedrag - munt

if aantal > 0 :
print aantal, 'x', munt

what i need is:
for example
the programm gives
68= 50*1
10*1
5*1
2*1
1*1
I need an additional code to get the "5" total of all the coins together.


Jul 18 '05 #3
If you look at this as a homework or not is of no interest to me but I like
the way you explained which way to go to find the resolution.
thanks (i solved it in a jiffy now)

"Paul Rubin" <http://ph****@NOSPAM.invalid> schreef in bericht
news:7x************@ruckus.brouhaha.com...
That sounds like a homework problem, so rather than write the code for
you, here's a hint -- use another variable, and update it every time
you decide how many coins of any specific size you'll use.

Jul 18 '05 #4
If you look at this as a homework or not is of no interest to me but I like
the way you explained which way to go to find the resolution.
thanks (i solved it in a jiffy now)

"djw" <do*****************@hp.com> schreef in bericht
news:40******@usenet01.boi.hp.com...
As this is obviously a class assignment of some sorts, I don't know how much help you are going to get (or should get) in directly writing the code.
But, what I will say is that you should be able to look at the way the code works now, how it keeps track of how many bills are needed for each
denomination (200, 100, etc), and apply the same idea to the total number
of bills required using another variable that is initialized before the
loop begins.

-d
broebel wrote:
hey,

for the real programmers amongst you, this may be really annoying but I've been learning the language for only two days.

this is my problem,
in this programm,which already works I now have to make a total count of
how many coins are used.
this program gives the total per coin. It should be a small peace of code (as explained in a tutorial i read, without the answer.)that counts the
total of all the coins.
I ve been searching for two days and for this kind of programm it really
seems kind of long.

thanks in advance

# Een bedrag gepast betalen met zo min mogelijk euromunten

bedrag = input ( 'Geef bedrag tussen 0 en 500 eurocent: ' )

for munt in 200, 100, 50, 20, 10, 5, 2, 1 :
aantal = 0

while bedrag >= munt :
aantal = aantal + 1
bedrag = bedrag - munt

if aantal > 0 :
print aantal, 'x', munt

what i need is:
for example
the programm gives
68= 50*1
10*1
5*1
2*1
1*1
I need an additional code to get the "5" total of all the coins
together.

Jul 18 '05 #5
djw
broebel wrote:
If you look at this as a homework or not is of no interest to me but I
like the way you explained which way to go to find the resolution.
thanks (i solved it in a jiffy now)


I think you missed my point (and Paul Rubin's). If this is indeed homework
or a class assignment, you should not be asking people on this newsgroup to
do the work for you. We are happy to give some small hints or some guidance
as a teacher or instructor would.

-d

Jul 18 '05 #6
"broebel" <co****************@skynet.be> wrote:
If you look at this as a homework or not is of no interest to me but I like
the way you explained which way to go to find the resolution.
thanks (i solved it in a jiffy now)


Now that it is solved it's fair game for anyone :-) I have no
information whether this is homework for you or not, and posting in a
public newsgroup defeats cheating.

Anton

def split(units,coins):
for c in coins :
n, units = divmod(units, c)
if n: yield c, n
if not units: raise StopIteration
raise ValueError, 'no change!'

def test():
coins = [200,100,50,20,10,5,2,1]
for i in range(501):
D = dict(split(i,coins))
nc = sum(D.values())
check = sum([c*n for c,n in D.items()])
print "%3i: %i coins:" %(i,nc) , D
assert check == i

if __name__=='__main__':
test()
Jul 18 '05 #7
H.V
"broebel" <co****************@skynet.be> wrote in message news:<40***********************@news.skynet.be>...
hey,

for the real programmers amongst you, this may be really annoying but I've
been learning the language for only two days.

this is my problem,
in this programm,which already works I now have to make a total count of how
many coins are used.
this program gives the total per coin. It should be a small peace of code
(as explained in a tutorial i read, without the answer.)that counts the
total of all the coins.
I ve been searching for two days and for this kind of programm it really
seems kind of long.

thanks in advance

# Een bedrag gepast betalen met zo min mogelijk euromunten

bedrag = input ( 'Geef bedrag tussen 0 en 500 eurocent: ' )

for munt in 200, 100, 50, 20, 10, 5, 2, 1 :
aantal = 0

while bedrag >= munt :
aantal = aantal + 1
bedrag = bedrag - munt

if aantal > 0 :
print aantal, 'x', munt

what i need is:
for example
the programm gives
68= 50*1
10*1
5*1
2*1
1*1
I need an additional code to get the "5" total of all the coins together.

--
An alternative to keeping track of coins as you go would be to store
your results in some kind of data structure : use a dict whose keys
are the coin type and whose values ate the number of each type of coin
needed. Then you can just add all the "values" . I like the data
centric approach . Your code doesn't seem to exploit any of the
convenient data structures at all .

sulf
Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Atz | last post by:
Hi to all ! 1.) Is there a way to make exe file from java class file ? 2.) I want to make multiple uninstalation of some files, under windows. E.g. instead of going into control panel ,...
0
by: Alexander F?hrmann | last post by:
Grüß euch! Wir haben hier in der Firma ein Problem mit Access! Sobald man im Access den VBA-Editor aufrufen will, kommt folgender fehler! -------------------- Runtime Error!
6
by: TIM | last post by:
for example i have one simple programm int main() { int test = NULL; while(1){ printf("%d\n",test); getch(); test++; }
2
by: Jan | last post by:
Hello! I am looking for a way to do a search&replace in ASCII-Files by a vb.net 2005 programm. Of coarse I can open the files, loop to every line, make a replace, and save the line. But I wonder...
16
by: Martin Jørgensen | last post by:
Hi, I've made a program from numerical recipes. Looks like I'm not allowed to distribute the source code from numerical recipes but it shouldn't even be necessary to do that. My problem is...
1
by: bparanj | last post by:
Hello, I have been a software developer for the past 10 years now. I get job descriptions that requires problem-solving skills as one of the most desirable skills in a candidate. But there are...
83
by: deppy_3 | last post by:
Hi.I am started learning Programm language C before some time.I am trying to make a programm about a very simple "sell shop".This programm hasn't got any compile problem but when i run it i face...
2
by: LordChaos | last post by:
Dear all, I am a newbie in Java, I got the following problem: I am going through a list of directories. The programm looks inside each directory for specific files and writes them in an...
2
by: tdr911turbo | last post by:
Find solution for your problem with powerful tips and tricks for your operating system http://windowsxpsp2pro.blogspot.com
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.