コンピューティングクラスで、GTIN-8バーコードを生成して検証するPythonプログラムを開発するタスクを設定しました。しかし、私の先生は非常に貧しく、何か手がかりがないので、クラスで助けを求めるのは本当に有効な選択肢ではありません。さらに、この割り当てを設定する前に、私のクラスはPythonの経験がほとんどなく、現在はPythonの初心者の定義です。 バーコードの生成と検証
def mainmenu():
print("1. Generate a barcode")
print("2. Validate a barcode")
print("3. Quit") #prints out 3 options for the user to select
while True: #loops over and over again
try: #handles exceptions
selection=int(input("Enter choice: ")) #tells user to enter a choice
if selection==1:
generate() #calls the function
break #terminates the loop
elif selection==2:
validate()
break
elif selection==3:
break
else:
print("Invalid choice. Enter 1-3")
mainmenu()
except ValueError: #if user enters a string, it will loop back
print("Invalid choice. Enter 1-3")
exit
def generate():
print("You have chosen to generate a barcode")
D1 = int(input("Please enter the first digit"))
D2 = int(input("Please enter the second digit"))
D3 = int(input("Please enter the third digit"))
D4 = int(input("Please enter the fourth digit"))
D5 = int(input("Please enter the fifth digit"))
D6 = int(input("Please enter the sixth digit"))
D7 = int(input("Please enter the seventh digit"))
timestogether = int('D1') * 3
print (timestogether)
anykey=input("Enter anything to return to main menu")
mainmenu()
def validate():
print("You have chosen to validate a barcode")
anykey=input("Enter anything to return to main menu")
mainmenu()
# recalls the main menu
mainmenu()
はこれまでのところ、私は彼らが生成したり、バーコードを検証するかどうかをユーザーに尋ねるメニューを開発している:とにかく、ここで私がこれまで持っているすべてのコードです。しかし、私は本当に次に何をすべきかはわかりません。ユーザがバーコードを生成したい場合、プログラムはユーザに7桁の数字を入力するよう要求しなければならず、次に7桁の数字を1より3だけ順番に掛けなければならない。次に合計を得るために結果を加算しなければならない。それは、10の最も近い等しいかより高い倍数から合計を引く必要があります。最後に、結果は8桁目(チェックデジット)になるので、プログラムは最後のバーコードを出力する必要があります。
ユーザーがバーコードを検証したい場合、プログラムはユーザーに8桁のコードを入力するように要求する必要があります。次に、3つのものと1つのものを用いて上記のように乗算処理を繰り返す必要があります。計算された数値をすべて加算し、結果が10の倍数であればバーコードが有効で、GTIN-8が有効であることを示すメッセージをユーザーに出力する必要があります。ただし、10の倍数でない場合、バーコードは無効で、エラーが出力されます。
とにかく、これを読んでいただきありがとうございました。ご協力いただければ幸いです。ここで