How do I add to variables in python?
Hey I am a new python developer and coding is just a new hobby of mine.
I was trying to make a butcher shop demo, where user can pick what kind of meat they want and pick how much (weight) of that type of meat and the program will keep track of how many kilograms of meat they bought as well as what kind of meat. At the very end, I'm planning to make a receipt for them which states what meats and prices. I got started with the project and I cam across a problem where I need to add to a variable to calculate the cost of the user. Any help with this would be appreciated! Thanks
variablename=integer, float, string... etc.
You can globalize a variable too!
global variablename which will make it so that you don’t need to constantly use
Here’s a link to help:https://www.learnpython.org/en/Variables_and_Types
please upvote or mark as answered if this helped!
when i was doing a project for a coding class i was trying to code the program to say grade=4th grade in variables but it says that grade isnt a good word for print and i am new to coding so can you make it easy?
cost_per_pound = int(x)
total_cost = int(input("How many pounds do you need?")) * cost_per_pound
If you want cents consider using floats instead of integers. I'd recommend taking the Python 3 course on sololearn.
Edit: After looking at your code, you'd be best off making a food class with a name and cost attribute. You could remove some repeated code this way.
If you're trying to calculate cost given the amount per kilogram and the amount entered then this might work
amtofmeat = float(input('Amount of Meat (kg) ')) #Get Amount of Meat from Console cost = amtofmeat * costperkilo #Multiply Amount Wanted by Amount per Kilo