## How to make a cash change calculaotr?

This is the place for queries that don't fit in any of the other categories.

### How to make a cash change calculaotr?

Hello
how can i make a change calculator?
for exmaple i want to buy an item thet cost 5.89\$ and in canada no more 1 cents so how can round the number to 5.90?
vadimak

Posts: 15
Joined: Wed May 01, 2013 1:07 pm

### Re: How to make a cash change calculaotr?

Code: Select all
`print(round(5.89, 1))`
we will be moving to python-forum.io on October 1 2016
more details here

metulburr

Posts: 2244
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

### Re: How to make a cash change calculaotr?

The point is i showed only example. the number will be random. and if its 3.32 i need to round this to 3.30. so how can i do it ?
vadimak

Posts: 15
Joined: Wed May 01, 2013 1:07 pm

### Re: How to make a cash change calculaotr?

The point is i showed only example. the number will be random. and if its 3.32 i need to round this to 3.30. so how can i do it ?

how about reading some tutorials!

3.3 * 5 is the same as 3.30 * 5, so if you put it in an equation it will be the same. Since you rounded it, the precision is gone anyways. However, if you are just wanting to display it in money format \$X.XX, then just use str.format()

Code: Select all
`import randomfor i in range(10):    num = random.uniform(1,10)    rounded = round(num,1)    print('{} was rounded to {:.2f}'.format(num, rounded))`
we will be moving to python-forum.io on October 1 2016
more details here

metulburr

Posts: 2244
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

### Re: How to make a cash change calculaotr?

Thank you Mek......here is my noobish correction of a noobish mistake

Code: Select all
`#example1print 'Enter total:'total = input()print '\$' + str((round(total,1)))`

or with a simple loop and clear statement

Code: Select all
`import osdef cls():  '''Clears any displayed data on screen    os.system(['clear', 'cls'][os.name == 'nt]) again = 1while again == 1:    print 'Enter Total:'    total = input()    print 'Rounded total \$' + str((round(total, 1)))        another = raw_input('Another Go? y/n')    if another == 'y':      cls()      pass    elif another == 'n':      comt +=1`

I'm still learning also
Last edited by Guitarman2010 on Fri May 10, 2013 1:23 pm, edited 3 times in total.
Guitarman2010

Posts: 22
Joined: Thu Mar 07, 2013 4:39 pm
Location: USA

### Re: How to make a cash change calculaotr?

Guitarman2010 wrote:Noobish way

Unfortunately wrongish way. Did you try to run it?

Code: Select all
`#exampleprint str('Enter total:') #You don't need to convert a string to a string.total = input() #You should never use input in python 2.x; use raw_input and convert your result.#String concatenation in print statements is discouraged, but you have a bigger problemprint str('\$') + (round(total,1)) #You converted the str to a str but didn't convert your float; this fails.`

-Mek
New Users, Read This
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Describe your problem; not your chosen solution.
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

### Re: How to make a cash change calculaotr?

Hello vadimak, what happened to your last thread about this idea? Did you follow the advice given there?
Due to the reasons discussed here we are moving to python-forum.net on October 1, 2016.

This forum will be closed. Please create an account at the new site to continue discussion.

IRC://irc.freenode.net/python-forum
Kebap

Posts: 689
Joined: Thu Apr 04, 2013 1:17 pm
Location: Germany, Europe

Return to General Coding Help

### Who is online

Users browsing this forum: Bing [Bot] and 11 guests