Python Forum
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Money Bags Program
#1
Hi all,
I need some help with adding some validation into my program. I need to make sure that the user cannot enter no prohibited characters into the inputs. For example, my program asks what coin type the user would like to use, the user should only be able to answer '1p', '2p' etc.

Thanks in advance.

startMenu = open('Menu.txt','r')
print(startMenu.read())
startMenu.close()
count = 0
def check(bag_weight, coin_type, bag_weight1):
    global count
    count = count+1
    x = bag_weight1[coin_type]
    y = x[1]
    if bag_weight > y:
        print("you have",int(bag_weight - y), "too many coins")
    else:
        print("you need to add",int(y - bag_weight), "coins")

def main():
    while True:
        print("you have checked", count, "bags.")
        y = input('do you want to check a bag?(Y/N)')
        if y.lower() == 'y':
            weight = float(input('how heavy is the bag(grams)?'))
            coin_Weight = {'1p' :[3.56, 100],'2p':[7.12, 50],'5p':[3.25,100],'10p':[6.5, 50],'20p':[5.0, 50],'50p':[8.00, 20],'£1':[9.50, 20],'£2':[12.00, 10]}
            coin_type = input('what type of coin is it?(1p, 2p, 5p, 10p, 20p, 50p, £1, £2)')
            bag_weight1 = coin_Weight[coin_type]
            bag_weight = weight/bag_weight1[0]
            print('there are', int(bag_weight), coin_type, 'coins in the bag.')
            check(bag_weight, coin_type, coin_Weight)
        else:
            print("Thank you for using this program")
            break

main()
Reply


Messages In This Thread
Money Bags Program - by PythonNoob123 - Jan-23-2017, 08:06 PM
RE: Money Bags Program - by Yoriz - Jan-23-2017, 10:16 PM
RE: Money Bags Program - by PythonNoob123 - Jan-23-2017, 10:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Money Global Variable saturnstars 9 6,955 Jun-03-2024, 02:46 PM
Last Post: LinkAiris
  I have this coding exercise to find how much money take Barrack Obama and Romney Mitt vasiliskarv 1 1,317 Mar-19-2024, 08:24 PM
Last Post: deanhystad
  Banking system - transferring money 3DEN 2 10,482 Dec-13-2019, 09:13 AM
Last Post: 3DEN

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020