A simple vending machine

Ad: This forum contains affiliate links to products on Amazon and eBay. More information in Terms and rules

ARTESH

Chief Master Sergeant
4,201
6,152
Aug 27, 2017
Tehran, Iran
Howdy!

Here is my First Homework, Learning Python Programming Language... I hope you Enjoy it.

Python:
print("A simple vending machine\n")
 
cake = 10
tea = 10
 
while tea > 0 or coffee > 0:
    print("Remaining Tea:",tea)
    print("Remaining Cake:",cake)
    print("\nWhat would you like?\n(1) Tea\n(2) Cake")
    selection = input("> ")
    if selection == '1':
        if tea > 0:
            print("\nHere is your Tea\n")
            tea -= 1
        else:
            print("\nI'm sorry, but we're all out of Tea\n")
    elif selection == '2':
        if cake > 0:
            print("\nHere is your Cake\n")
            cake -= 1
        else:
            print("\nI'm sorry, but we're all out of Cake\n")      
       
else:
    print("Remaining Tea:",tea)
    print("Remaining Cake:",cake)  
    print("Sold out")

Copy Paste the Text here, to test / try:

 
Last edited:
Nice.

p-1.jpg
 
Started on a Trash-80, first bought myself an Amiga 500.

Now, alas, it's nothing but Windog but I do still have a real computer: a Sun Blade 2500 Silver workstation running Solaris 10 for when I need a break from barely functional garbage from Redmond.
 
Started on a Trash-80, first bought myself an Amiga 500.

Now, alas, it's nothing but Windog but I do still have a real computer: a Sun Blade 2500 Silver workstation running Solaris 10 for when I need a break from barely functional garbage from Redmond.
I also used Amiga now happily running Linux, running my own desktop. No need for Windhog at all.
 
Very nice first attempt. However there is a minor bug in your code. In the while loop you have coffee, which is undefined. Your program won't fail until you run out of tea and have to test for coffee. Maybe coffee should be cake?
Thank a lot, mate. I'm working on newer version with extended menu, right now.
 
Great! Python is my favourite program language. I've been programming in Python professionally since the old 2.6 version in 2009. If you need any help, just ask.
Thanks.

Just started almost mid-September ... It seems lot easier than JAVA.
 

Users who are viewing this thread

Back