From c580ecc6e4fd263d1bf08b645a21a6c1ac870893 Mon Sep 17 00:00:00 2001 From: Rsclub2 2 Date: Thu, 7 Apr 2022 14:43:17 +0200 Subject: [PATCH] 1 --- .../Getränke_automat_2.py | 195 ++++++++++++++++++ .../Getränkeautomat.db | Bin 0 -> 8192 bytes .../Getränke_automat_1/Beipielautomat.md | 14 ++ .../Getränke_automat_1/Beispielautomat.py | 45 ++++ .../07.04.2022/Getränke_automat_1/cola.txt | 1 + .../07.04.2022/Getränke_automat_1/saft.txt | 1 + .../07.04.2022/Getränke_automat_1/wasser.txt | 1 + 3. Übungen/31.03.2022/while-übung-2.py | 9 + 8 files changed, 266 insertions(+) create mode 100644 3. Übungen/07.04.2022/Getränke und Snack automat/Getränke_automat_2.py create mode 100644 3. Übungen/07.04.2022/Getränke und Snack automat/Getränkeautomat.db create mode 100644 3. Übungen/07.04.2022/Getränke_automat_1/Beipielautomat.md create mode 100644 3. Übungen/07.04.2022/Getränke_automat_1/Beispielautomat.py create mode 100644 3. Übungen/07.04.2022/Getränke_automat_1/cola.txt create mode 100644 3. Übungen/07.04.2022/Getränke_automat_1/saft.txt create mode 100644 3. Übungen/07.04.2022/Getränke_automat_1/wasser.txt create mode 100644 3. Übungen/31.03.2022/while-übung-2.py diff --git a/3. Übungen/07.04.2022/Getränke und Snack automat/Getränke_automat_2.py b/3. Übungen/07.04.2022/Getränke und Snack automat/Getränke_automat_2.py new file mode 100644 index 0000000..06bf920 --- /dev/null +++ b/3. Übungen/07.04.2022/Getränke und Snack automat/Getränke_automat_2.py @@ -0,0 +1,195 @@ +# Getränke und Snackautomat +# Uses database to store the products and the amount of money + +# Imports +import sqlite3 +import os +import sys +import time +import datetime + +# Make a new database +conn = sqlite3.connect('Getränkeautomat.db') +c = conn.cursor() +# Create a table for the products +c.execute("CREATE TABLE IF NOT EXISTS products (id INTEGER PRIMARY KEY, name TEXT, price REAL)") + +# Make an admin mode to add new products and change the price and add an id +def admin_mode(): + weiter_admin=True + while (weiter_admin==True): + # Print the admin menu + print("1. Add Product") + print("2. Change Price") + print("3. Delete Product") + # Ask for the user input + admin_input=input("Please choose an option: ") + # Check if the input is a number + try: + admin_input=int(admin_input) + except ValueError: + print("Please enter a number") + continue + # Check if the input is in the range of the admin menu + if (admin_input<1 or admin_input>4): + print("Please enter a number between 1 and 4") + continue + # Add a new product + # Ask for the product name + # Ask for the product price + # Ask for the product id + # Add the product to the database + if (admin_input==1): + product_name=input("Please enter the product name: ") + product_price=input("Please enter the product price: ") + product_id=input("Please enter the product id: ") + c.execute("INSERT INTO products (name, price, id) VALUES (?, ?, ?)", (product_name, float(product_price), int(product_id))) + conn.commit() + print("Product added") + continue + # Change the price of a product + # Ask for the product id + # Ask for the new price + # Change the price in the database + # Print the old price and the new price + if (admin_input==2): + product_id=input("Please enter the product id: ") + new_price=input("Please enter the new price: ") + c.execute("UPDATE products SET price=? WHERE id=?", (float(new_price), int(product_id))) + conn.commit() + print("Old price: " + str(c.execute("SELECT price FROM products WHERE id=?", (int(product_id),)).fetchone()[0])) + print("New price: " + str(new_price)) + continue + # Delete a product + # Ask for the product id + # Delete the product from the database + if (admin_input==3): + product_id=input("Please enter the product id: ") + c.execute("DELETE FROM products WHERE id=?", (int(product_id),)) + conn.commit() + print("Product deleted") + continue + # Ask if the user wants to continue in the admin mode + if (admin_input==4): + weiter_admin=False + normal_mode() + +# Make the normal operation mode +def normal_mode(): + print("Willkommen beim Getränke und Snackautomat") + print("Drücken Sie 1 um zu starten") + print("Drücken 2 um zum Adminmodus zu wechseln") + print("Drücken 3 um das Programm zu beenden") + # Ask for the user input + user_input=input("Please choose an option: ") + # Check if the input is a number + try: + user_input=int(user_input) + except ValueError: + print("Bitte geben Sie eine Nummer ein") + return + # Check if the input is in the range of the admin menu + if user_input==2: + # Ask for the admin password + admin_password=input("Please enter the admin password: ") + # Check if the password is correct + if (admin_password=="admin"): + # Start the admin mode + admin_mode() + return + else: + print("Wrong password") + return + if user_input==3: + # Exit the program + sys.exit() + if user_input==1: + sum_of_price=0 + normal_continue=True + while (normal_continue==True): + # Print all the products and their price and the id of the product + for row in c.execute("SELECT * FROM products"): + print(row) + # Ask for the product id + product_id=input("Bitte Nummer des gewünschten Produktes eingeben: ") + # Check if the product id is in the database + if (c.execute("SELECT * FROM products WHERE id=?", (int(product_id),)).fetchone()==None): + print("Product nicht gefunden") + return + # Get the price of the product + product_price=c.execute("SELECT price FROM products WHERE id=?", (int(product_id),)).fetchone()[0] + # Ask the amount of the product + product_amount=int(input("Bitte Anzahl des Produktes Eingeben: ")) + sum_of_price=product_price*product_amount + # Print the price of the sum + print("Summe:%s€" % sum_of_price) + # Ask if the user wants to continue + if (input("Weiter Einkaufen? (j/n): ")=="n"): + normal_continue=False + payment(sum_of_price) + return +# Define a function to handle the payment +def payment(sum_of_price): + # Print the price of the sum + print("Summe: %s€" % sum_of_price) + # Ask for the money put in the machine + money_in_machine=input("Bitte Geld eingeben: ") + # Check if the money is a number + try: + money_in_machine=int(money_in_machine) + except ValueError: + print("Bitte geben Sie eine Nummer ein") + return + # Check if the money is enough + if (money_in_machine*{uR#V@q1)n@$rk6^T`=v&uTkJ8*-_hKm`B}hf9RFJ!+X=muO-h_pXdl<5Ci^{|^}D%U`Vj~~00Izz00bZa0SG_<0uX=z I1pZjy1B44FL;wH) literal 0 HcmV?d00001 diff --git a/3. Übungen/07.04.2022/Getränke_automat_1/Beipielautomat.md b/3. Übungen/07.04.2022/Getränke_automat_1/Beipielautomat.md new file mode 100644 index 0000000..1eabf4c --- /dev/null +++ b/3. Übungen/07.04.2022/Getränke_automat_1/Beipielautomat.md @@ -0,0 +1,14 @@ +# Getränkeautomat +- Auswahl + - Cola (1,50€) + - Wasser (1,00€) + - Saft (2,00€) + +- Anzahl + +- Weiteres Getränk? + - Ja (von vorne) + - Nein (Ausgabe Preis) + +- Ausgabe Preis + \ No newline at end of file diff --git a/3. Übungen/07.04.2022/Getränke_automat_1/Beispielautomat.py b/3. Übungen/07.04.2022/Getränke_automat_1/Beispielautomat.py new file mode 100644 index 0000000..86ede85 --- /dev/null +++ b/3. Übungen/07.04.2022/Getränke_automat_1/Beispielautomat.py @@ -0,0 +1,45 @@ + # Programm, welches einen Getränkeatuomat simuliert +weiter_machen = True +gesamtpreis = 0 +preis = 0 + +f1 = open("cola.txt") +f2 = open("wasser.txt") +f3 = open("saft.txt") + +cola = float(f1.read()) +wasser= float(f2.read()) +saft= float(f3.read()) +while (weiter_machen==True): + #Getränkeauswahl + print("Wählen Sie ein Getränk!") + print("1. Cola %s€"%(cola)) + print("2. Wasser %s€"%(wasser)) + print("3. Saft %s€"%(saft)) + + auswahl=int(input("Ihre Auswahl:")) # Nutzereingabe + if auswahl==1: + preis=cola + elif auswahl==2: + preis=wasser + elif auswahl==3: + preis=saft + else: + print("ERREUR, please nochmal from Vorne") + continue + # Anzahl der Getränke + anzahl=int(input("Wie viele Getränke wollen Sie? ")) + preis=preis*anzahl + gesamtpreis=gesamtpreis+preis + print("Ihr Gesamtpreis beträgt %s€"%(gesamtpreis)) # Gesamtpreis ausgeben + + # Weiteres Getränk? + weiter=input("Möchten Sie weitere Getränke bestellen? (j/n)") + if weiter=="j": + weiter_machen=True + continue + elif weiter=="n": + break + else: + print("ERREUR, please nochmal from Vorne") + continue diff --git a/3. Übungen/07.04.2022/Getränke_automat_1/cola.txt b/3. Übungen/07.04.2022/Getränke_automat_1/cola.txt new file mode 100644 index 0000000..78c3960 --- /dev/null +++ b/3. Übungen/07.04.2022/Getränke_automat_1/cola.txt @@ -0,0 +1 @@ +1.50 \ No newline at end of file diff --git a/3. Übungen/07.04.2022/Getränke_automat_1/saft.txt b/3. Übungen/07.04.2022/Getränke_automat_1/saft.txt new file mode 100644 index 0000000..8ac712f --- /dev/null +++ b/3. Übungen/07.04.2022/Getränke_automat_1/saft.txt @@ -0,0 +1 @@ +2.00 \ No newline at end of file diff --git a/3. Übungen/07.04.2022/Getränke_automat_1/wasser.txt b/3. Übungen/07.04.2022/Getränke_automat_1/wasser.txt new file mode 100644 index 0000000..945273a --- /dev/null +++ b/3. Übungen/07.04.2022/Getränke_automat_1/wasser.txt @@ -0,0 +1 @@ +1.00 \ No newline at end of file diff --git a/3. Übungen/31.03.2022/while-übung-2.py b/3. Übungen/31.03.2022/while-übung-2.py new file mode 100644 index 0000000..2006732 --- /dev/null +++ b/3. Übungen/31.03.2022/while-übung-2.py @@ -0,0 +1,9 @@ +# Programm, welches wiederholenden um 1 erhöht, startwert=1, obergrenze vom nutzer festglegt +# Definieren +x=1 +# Eingabe +obergrenze=float(input("Maximalen Wert festlegen:")) + +while x