Browse Source

assignment dy 21

Mahiva 1 day ago
parent
commit
ca088e46fe
5 changed files with 77 additions and 5 deletions
  1. 4 2
      day 11
  2. 1 2
      dy 1.py
  3. 1 1
      dy2.py
  4. 13 0
      kazi_yetu/students.py
  5. 58 0
      shopping cart

+ 4 - 2
day 11

@@ -10,11 +10,11 @@
 #2 LOGIN SYSTEM
 #Accept username and password
 #USERNAME: THURSDAY
-#PASSWORD: 90DAYS
+#PASSWORD: 9DAYS
 
 #3 MULTIPLICATION TABLE
 
-Grade = input("Enter your grade: ") 
+Grade = int(input("Enter your grade: ")) 
 
 if 80<=Grade<=100:
     print("A")
@@ -31,6 +31,8 @@ elif 40>Grade:
 else:
     print("error")  
 
+
+
     
 
 

+ 1 - 2
dy 1.py

@@ -6,5 +6,4 @@ age=20
 print(age)
 print(f"I am {age}")
 print("I am "+str(age))
-print ("I am", age , "years")
-print ("I am 20") 
+print ("I am", age , "years")

+ 1 - 1
dy2.py

@@ -1 +1 @@
-print ("Today is dy 2")s
+print("Today is dy 2")

+ 13 - 0
kazi_yetu/students.py

@@ -0,0 +1,13 @@
+def add_student(name, university, course, filename):
+    student = {
+        "name": "Paul",
+        "university": "UON",
+        "course": "Information systems",
+        "filename": "students.txt"
+    }
+
+    print("Student added successfully!")
+
+def view_students(students):
+    for student in students:
+        print(f"Name: {student['name']}, University: {student['university']}, Course: {student['course']}")

+ 58 - 0
shopping cart

@@ -0,0 +1,58 @@
+
+products ={"laptop": 75000,
+           "smartphone": 30000,
+           "headphones": 5000,
+           "keyboard": 3500,
+           "mouse": 2000
+}
+
+cart = []
+
+def view_products():
+    for product, price in products.items():
+        print(f"{product}: ${price}")
+
+def add_to_cart(product_name):
+    if product_name in products:
+        cart.append(product_name)
+        print(f"{product_name}(s) added to your cart.")
+    else:
+        print("Product not found.") 
+
+def view_cart():
+    print("Your cart contains:")
+    for product in cart:
+        print(f"- {product}: ${products[product]}")
+
+def total_cart_value():
+    total = sum(products[product] for product in cart)
+    print(f"Total value of your cart: ${total}") 
+
+def exit_cart():
+    print("Exiting the shopping cart. Thank you for shopping with us!")
+
+while True:
+    print("\nWelcome to the Shopping Cart!")
+    print("1. View products")
+    print("2. Add product to cart")
+    print("3. View cart")
+    print("4. Exit")
+    user_choice = input("Enter your choice (1-4): ")
+
+    if user_choice == "1":
+        view_products()
+
+    elif user_choice == "2":
+        product_name = input("Enter the product name to add to cart: ")
+        add_to_cart(product_name)
+
+    elif user_choice == "3":
+        view_cart()
+
+    elif user_choice == "4":
+        exit_cart()
+        break
+
+    else:
+        print("Invalid choice. Please enter a number from 1 to 4. ")
+