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.
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,
Subreddit
Post Details
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnpython...