Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Beginner project code review/critique request: Coin estimator by weight.
Post Body

Hey everyone,

Continuing along my journey with learning Python - trying to get through this list of beginner projects(https://docs.google.com/document/d/1TyqD2_oDtiQIh_Y55J5RfeA91JJECc97xYIKM112H9I/edit) and I just completed the coin estimator by weight (https://www.reddit.com/r/beginnerprojects/comments/1idqw1/project_coin_estimator_by_weight/). Here is what I came up with for my solution:

dime_weight = int(input('How much do all your dimes weigh in grams? '))
nickel_weight = int(input('How much do all your nickels weigh in grams? '))
quarter_weight = int(input('How much do all your quarters weigh grams? '))
penny_weight  = int(input('How much do all your pennies weigh in grams? '))

dime_count = round(dime_weight / 2.268)
nickel_count = round(nickel_weight / 5)
quarter_count = round(quarter_weight / 5.670)
penny_count = round(penny_weight / 2.500)

print('you have '   str(dime_count)   ' dimes')
print('you have '   str(nickel_count)   ' nickels')
print('you have '   str(quarter_count)   ' quarters')
print('you have '   str(penny_count)   ' pennies')

dime_wrapper = round(dime_count / 50)
if dime_wrapper < 1:
    dime_wrapper = 1
nickel_wrapper = round(nickel_count / 40)
if nickel_wrapper < 1:
    nickel_wrapper = 1
quarter_wrapper = round(quarter_count / 40)
if quarter_wrapper < 1:
    quarter_wrapper = 1
penny_wrapper =  round(penny_count / 50)
if penny_wrapper < 1:
    penny_wrapper = 1

print('You need '   str(dime_wrapper)   ' wrappers for your dimes')
print('You need '   str(nickel_wrapper)   ' wrappers for your nickels')
print('You need '   str(quarter_wrapper)   ' wrappers for your quarters')
print('You need '   str(penny_wrapper)   ' wrappers for your pennies')

total_value = (dime_count * .10)   (nickel_count * .05)   (quarter_count * .25)   (penny_count * .01)
print('You have '   str(total_value)   ' dollars worth of coins.')

Overall this one didn't seem too challenging, it was just a matter of setting/calculating variables correctly. What are some improvements I could make? Maybe I am converting my variables to strings too often and/or using string variable string where I don't need to? I don't really like what I did with the

if dime_wrapper < 1:
    dime_wrapper = 1

part of the program.. I did this because if I entered a value that resulted in less than the amount of coins needed to fill a single roll, it would say I needed 0 rolls. However, now someone can enter 0 for their weight of a coin and the program will still suggest they need 1 roll. I thought about using an if elic statement, but started getting stuck.. currently my brain is thinking something like:

if dime_count == 0:
    dime_wrapper = 0
elif dime_weight > 0:
    dime_wrapper = round(dime_count / 50)
if dime_wrapper < 1 and dime_count > 0:
    dime_wrapper = 1

That way if there are no dimes, it sets dime_wrapper to 0, if there are dimes, it calculates how many wrappers are needed. If the number of coins dont fill 1 wrapper, but are more than 0, then it sets the dime_wrapper to 1...

I haven't tested this latest part yet, starting to confuse myself!

Anyways, looking for any feedback - as always, very much appreciated.

Take care,

Author
Account Strength
100%
Account Age
5 years
Verified Email
Yes
Verified Flair
No
Total Karma
11,540
Link Karma
432
Comment Karma
11,084
Profile updated: 4 days ago
Posts updated: 2 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
5 years ago