Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Rogier Leegwater
5,589 PointsI was trying to create a a drink slot-machine. When i select an item from menu it doesn't show it. Help please. my code
!/usr/bin/env python3
import sys import datetime import os from collections import OrderedDict #to keep options in an order
from peewee import *
db = SqliteDatabase('drinks.db')
class Entry(Model): coins = [] content = TextField() timestamp = DateTimeField(default=datetime.datetime.now) #no prethenses, date is use as function which will called
class Meta: database = db
def initialize(): """Create database and tables if not exist.""" db.connect() db.create_tables([Entry], safe=True)
def clear(): os.system('cls' if os.name == 'nt' else 'clear') #call cls if windows, clear if on linux, mac
def menu_loop(): """Show the Menu""" choice = None
while choice != 'q': q = quit clear() print("Enter 'q' to quit.") for key, value in menu.items(): print('{}) {}'.format(key, value.doc)) choice = input('Action: ')
if choice in menu:
clear()
menu[choice]()
for entry in entries: timestamp = entry.timestamp.strftime('%A %B %d, %Y %I:%M%p') #%A weekday Bmonth d=nr I=h p=a orp.m clear() print(timestamp) print('='*len(timestamp)) print(entry.content) print('\n\n'+'='*len(timestamp)) print('n) next entry') print('d) delete entry') print('q) return to main menu')
next_action = input('Action: [Nq] ').lower().strip()
if next_action == 'q':
break
elif choice == '1':
price = '2.-fr'
print("Cola selectetd, Please insert: 2.-fr to purchase product")
input(coins.int + ' = ')
if coins == '2':
Print("Thank You, see u")
elif coins < 2:
Print("amount is not equals to {}.".format(price))
elif coins > 2:
Print("please take your change:" + coins - price)
elif next_action == '2':
print("No entries available, press a to create new")
elif next_action == '3':
print("No entries available, press a to create new")
def cola():
"""select 1 for cola."""
print("Enter entry. Press Ctrl+d when finished")
price = '2.-fr'
if choice == '1':
print("Cola selectetd, Please insert: 2.-fr to purchase product")
input(coins.int + ' = ')
if coins == '2':
Print("Thank You, see u")
elif coins < 2:
Print("amount is not equals to {}.".format(price))
elif coins > 2:
Print("please take your change:" + coins - price)
def fanta(): """select 2 for fanta.""" print("Enter entry. Press Ctrl+d when finished") data = sys.stdin.read().strip() #capture users input
def sprite(): """select 3 for sprite.""" print("Enter entry. Press Ctrl+d when finished") data = sys.stdin.read().strip() #capture users input
menu = OrderedDict([ # OrderedDict add things as a list ('1', cola), ('2', fanta), ('3', sprite),
])
if name == 'main': #prevent code from being executed when you import a module initialize() menu_loop()
1 Answer
Josh Keenan
20,315 PointsTagging Chris Freeman to fix formatting, can't tell what the bug is but I have an idea.