2016-10-24 7 views
-1

私はGTIN-8を使ってショッピングリストを作るつもりです。私の問題は、ユーザーに数字(以下のオプションからGTIN-8コード)を入力させ、その番号を取得してプログラムを入手し、特定のデータベースで検索してその番号が等しい項目を表示します。たとえば、次のように12345670 2におけるユーザ入力場合、プログラムは出力GTIN 8コードを使ってショッピングリストを作成

12345670 Hammer 2 4.50 
Subtotal     9.00 

マイコードは

があるであろう。

print("Hi There! Welcome to sSpecialists!") 
print("To start shopping, note down what you want to buy and how much of it") 
print("Here are the purchasable items") 

print("~~~~~") 

print("12345670 is a hammer (£4.50)") 
print("87654325 is a screw driver (£4.20)") 
print("96385272 is a pack of 5 iron screws (£1.20)") 
print("74185290 is pack of 20 100mm bolts (£1.99)") 
print("85296374 is a pack of 6 walkers crisps (£1)") 
print("85274198 is haribo pack (£1)") 
print("78945616 is milk (£0.88)") 
print("13246570 is a bottle of evian water (£0.99)") 
print("31264570 is kitkat original (£0.50)") 
print("91537843 is a cadbury bar (£1)") 

print("~~~~~") 

response = input("To view more of our items type more, else no: ") 
if response == 'more': 
    print("~~~~~") 
    print("45762147 is a 20 pack of sausages (£2.49)") 
    print("19348629 is a toy lion (£1.20)") 
    print("34821565 is a pack of 7 beef burgers (£1.20)") 
    print("48613545 is pack of 10 fish fingers (£1.99)") 
    print("46729811 is 500ml of heinz mayonnaise (£1)") 
    print("48613255 is 500ml of heinz ketchup (£1)") 
    print("31750677 is youghurt (£0.88)") 
    print("13246570 is 500ml of tropical juice (£0.99)") 
    print("76136948 is adult bmx bike (£499)") 
    print("76153242 is a sony ps4 (£249)") 
    print("46821799 is adult bmw i8 (£89,000)") 
    print("01352474 is a jar of pickles (£1)") 
    print("98523153 is a 20 pack of adult diapers (£7)") 
    print("18648515 is £20 psn card (£19.99)") 

if response == 'no': 
    print(" ") 
print("Alright, now start typing what you want to order") 
print("Include the amount with a spacing") 
print("For example 12345670 2 would be two hammers") 
print("And when you're done, type 'END' to finish") 
print("Start your orders") 
print(" ") 

full_list = " " 
orders = [] 
while full_list != "END": 
    full_list = input("Enter your order: ") 
    if full_list != "END": 
     orders.append(full_list)   

I入力にユーザ入力を取得する方法が必要GTINコードを作成し、それを書いたアイテムとしてユーザーに返します。これはPython 3.5です。

+0

あなたのコードは、データベース駆動型ではない単なる印刷ステートメントです。私はあなたがsqliteと基本的なデータベース設計のようなものを調べることをお勧めします。あなたに正しい方向にあなたを導く例がたくさんあります。さもなければ、この質問は本当にそうではありません。 – CodeLikeBeaker

答えて

-1
BOARD_SIZE = 8 

class BailOut(Exception): 
    pass 

def validate(queens): 
    left = right = col = queens[-1] 
    for r in reversed(queens[:-1]): 
     left, right = left-1, right+1 
     if r in (left, col, right): 
      raise BailOut 

def add_queen(queens): 
    for i in range(BOARD_SIZE): 
     test_queens = queens + [i] 
     try: 
      validate(test_queens) 
      if len(test_queens) == BOARD_SIZE: 
       return test_queens 
      else: 
       return add_queen(test_queens) 
     except BailOut: 
      pass 
    raise BailOut 

queens = add_queen([]) 
print queens 
print "\n".join(". "*q + "Q " + ". "*(BOARD_SIZE-q-1) for q in queens) 

33 lines: "Guess the Number" Game (edited) from http://inventwithpython.com 

import random 

guesses_made = 0 

name = raw_input('Hello! What is your name?\n') 

number = random.randint(1, 20) 
print 'Well, {0}, I am thinking of a number between 1 and 20.'.format(name) 

while guesses_made < 6: 

    guess = int(raw_input('Take a guess: ')) 

    guesses_made += 1 

    if guess < number: 
     print 'Your guess is too low.' 

    if guess > number: 
     print 'Your guess is too high.' 

    if guess == number: 
     break 

if guess == number: 
    print 'Good job, {0}! You guessed my number in {1} guesses!'.format(name, guesses_made) 
else: 
    print 'Nope. The number I was thinking of was {0}'.format(number) 




Ur wlcm 
関連する問題