So I'm trying to make this program where if a user inputs their name, type of coin and weight of coin bag (which you put the coins in which is only LIMITED to a certain amount of coins), it will give or display the amount of coins which needed to be added or removed if the input of weight is too high or low. I'm also trying to make it if the bag isn't filled up, more coins will be added, the bag has to be full and also CAN NOT contain any other TYPE of coin. For example, a 1 Pence coin bag can only have 1 Pence coins in it.
I have managed to do this already, HOWEVER, the amount of repetitive code I would use is insane and it has its limits, like if the user has inputted more than 107* more pennies, I would have to write all of the same repetitive code up to 107. I'm looking for a way to make this algorithm work without using more than 50 lines of code FOR each coin.
Please provide a solution below as I can not find any way how to do this and explain how it works, I'm very new to python.
Please note, that it is IMPOSSIBLE for the user to add any other type of coin to a bag made for another coin. For example, if the user inputs the coin type of '1 Pence', and the Bag Weight is equals to a 1PenceFullBag + 2PenceCoin, it would just print 'unrecognized type of coin added to bag'. I don't need the program that specific.
I'm using Python2.x and I have thought about using loops but I'm not sure how to enforce it.
My main aim is to make it so my program will work out how many coins of that specific chosen type needed to be added or removed for it to equal to the bag weight of the chosen inputted coin, for an unlimited amount of times. I just can't figure it out.
I have managed to do this already, HOWEVER, the amount of repetitive code I would use is insane and it has its limits, like if the user has inputted more than 107* more pennies, I would have to write all of the same repetitive code up to 107. I'm looking for a way to make this algorithm work without using more than 50 lines of code FOR each coin.
Please provide a solution below as I can not find any way how to do this and explain how it works, I'm very new to python.
Please note, that it is IMPOSSIBLE for the user to add any other type of coin to a bag made for another coin. For example, if the user inputs the coin type of '1 Pence', and the Bag Weight is equals to a 1PenceFullBag + 2PenceCoin, it would just print 'unrecognized type of coin added to bag'. I don't need the program that specific.
I'm using Python2.x and I have thought about using loops but I'm not sure how to enforce it.
My main aim is to make it so my program will work out how many coins of that specific chosen type needed to be added or removed for it to equal to the bag weight of the chosen inputted coin, for an unlimited amount of times. I just can't figure it out.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
one_pence_weight = 3.56 two_pence_weight = 7.12 five_pence_weight = 3.25 ten_pence_weight = 6.50 #These values are the weight of one coin. twenty_pence_weight = 5.00 fifty_pence_weight = 8.00 one_pound_weight = 8.75 two_pound_weight = 12.00 one_pence_bag = 356.00 two_pence_bag = 360.50 five_pence_bag = 325.00 ten_pence_bag = 325.00 ##These values are the weight of a full coin bag. twenty_pence_bag = 250.00 fifty_pence_bag = 160.00 one_pound_bag = 175.00 two_pound_bag = 120.00 ##This code below is what I'm trying to achieve, but as you can see, ##it would take me forever to do this for each and every single coin and ##isn't an infinite amount of adding / removing def verify(final_coin, final_weight): if final_coin = = "1 Pence" and final_weight = = one_pence_bag: print ( "Bag Correct and has no added or removed coins" ) if final_coin = = "1 Pence" and final_weight = = one_pence_bag - one_pence_weight: print ( "Bag incorrect and has added one 1p coin" ) if final_coin = = "1 Pound" and final_weight = = one_pound_bag - one_pound_weight: print ( "Bag inorrect and has added one 1Pound coin" ) else : pass verify(coin_user_input, coin_weight_input) |