diff --git a/Students/Nishan/python/even odd.py b/Students/Nishan/python/even odd.py new file mode 100644 index 0000000..9b0b4be --- /dev/null +++ b/Students/Nishan/python/even odd.py @@ -0,0 +1,6 @@ +num = int(input("Enter a number: ")) + +if num % 2 == 0: + print("Even number") +else: + print("Odd number") \ No newline at end of file diff --git a/Students/Nishan/python/task.py b/Students/Nishan/python/task.py new file mode 100644 index 0000000..719e450 --- /dev/null +++ b/Students/Nishan/python/task.py @@ -0,0 +1,44 @@ +#1.can vote or cannot vote +print("Enter your age:") +age = int(input()) +if age >= 18: + print("You can vote.") +else: + print("You cannot vote.") + #Gym memberships are priced based on age: $25 for adults (18 and over), $15 for children. Everyone gets a $5 discount on januarry + +print("Enter your age:") +age = int(input()) +if age >= 18: + price = 25 - 5 + print(f"Your gym membership price is: ${price}") +else: + price = 15 - 5 + print(f"Your gym membership price is: ${price}") + +#3.grade calculator loop + conditional statements +print("Enter your score:") +score = int(input()) +if score >= 90: + print("Your grade is: A") +elif score >= 80: + print("Your grade is: B") +elif score >= 70: + print("Your grade is: C") +elif score >= 60: + print("Your grade is: D") +else: + print("Your grade is: F") + + #4.password strength checker (8 characters, 1 uppercase, 1 lowercase, 1 number, 1 special character) +import re +print("Enter your password:") +password = input() +if (len(password) >= 8 and + re.search(r'[A-Z]', password) and + re.search(r'[a-z]', password) and + re.search(r'[0-9]', password) and + re.search(r'[@$!%*?&]', password)): + print("Your password is strong.") +else: + print("Your password is not strong.") \ No newline at end of file diff --git a/Students/Nishan/python/task1.py b/Students/Nishan/python/task1.py new file mode 100644 index 0000000..21c15a4 --- /dev/null +++ b/Students/Nishan/python/task1.py @@ -0,0 +1,95 @@ +""" The Smart Checkout System +Objective: Create a python program that simulates a simple shopping cart checkout process. + +Instructions for Students: +Write a code script that performs the following steps in order: + +Setup the Store: + +Create a const variable for walletBalance and set it to 5000. +Create an array called cartItems containing three prices: [500, 1200, 350]. +Manage the Cart (Array Operations): + +A new item is added! Use .push() to add a price of 2000 to the cart. +Oops, that item is too expensive. Use .pop() to remove the last item. +Create a new array called recommendedItems with prices [100, 200]. +combine recommendedItems and cartItems into a new array called finalCart using the Spread Operator (...). +Calculate Totals (Math & Operators): + +Calculate the sum of the prices in finalCart (Hint: since we don't have loops yet, access them manually like finalCart[0] + finalCart[1]...). +Store this sum in a variable totalPrice. +Add a 10% tax to the logic. Update totalPrice to include the tax. +Round the totalPrice to 2 decimal places using .toFixed(). +Coupon Code Handling (String Manipulation): + +Create a variable couponCode with the messy value " DisCOunT10 ". +Clean up the code: Remove the whitespace using .trim() and convert it to uppercase. +If the cleaned code is "DISCOUNT10", subtract 500 from the totalPrice. +Final Decision (Conditionals): + +Write an if/else statement: +If totalPrice is less than or equal to walletBalance: Console log "Purchase Successful! New Balance: [Remaining Amount]". +Else: Console log "Insufficient Funds! You need [Missing Amount] more." +Receipt Generation (Randomness): + +Generate a random Order ID between 1 and 100 using Math.random() and Math.floor(). +Console log a receipt message using Template Literals (backticks): Order [ID] confirmed. Thank you for shopping! +""" +# The Smart Checkout System + +# 1. Setup the Store +walletBalance = 5000 +cartItems = [500, 1200, 350] + +# 2. Manage the Cart (List Operations) + +cartItems.append(2000) + +cartItems.pop() +recommendedItems = [100, 200] +finalCart = cartItems + recommendedItems + +print("Final Cart:", finalCart) + +# 3. Calculate Totals (Math & Operators) +totalPrice = ( + finalCart[0] + + finalCart[1] + + finalCart[2] + + finalCart[3] + + finalCart[4] +) + +totalPrice = totalPrice + (totalPrice * 0.10) + +totalPrice = round(totalPrice, 2) + +print("Total Price with Tax:", totalPrice) + +# 4. Coupon Code Handling (String Manipulation) + +couponCode = " DisCOunT10 " +couponCode = couponCode.strip().upper() + +print("Cleaned Coupon Code:", couponCode) + +if couponCode == "DISCOUNT10": + totalPrice -= 500 + +print("Final Price After Discount:", totalPrice) + +# 5. Final Decision (Conditionals) + +if totalPrice <= walletBalance: + remainingAmount = walletBalance - totalPrice + print(f"Purchase Successful! New Balance: {remainingAmount}") +else: + missingAmount = totalPrice - walletBalance + print(f"Insufficient Funds! You need {missingAmount} more.") + +# 6. Receipt Generation (Randomness) + +import random +orderID = random.randint(1, 100) + +print(f"Order {orderID} confirmed. Thank you for shopping!") \ No newline at end of file diff --git a/Students/Nishan/python/try.py b/Students/Nishan/python/try.py new file mode 100644 index 0000000..76f4774 --- /dev/null +++ b/Students/Nishan/python/try.py @@ -0,0 +1,15 @@ +num1 = float(input("Enter the first number: ")) + +choice = input("Enter the operation (+, -, *, /): ") +num2 = float(input("Enter the second number: ")) +if choice == '+': + result = num1 + num2 +elif choice == '-': + result = num1 - num2 + +elif choice == '*': + result = num1 * num2 +elif choice == '/': + result = num1 / num2 + +print("The result is:", result)