Skip to content

Commit 7be3667

Browse files
authored
Add files via upload
1 parent 18a88c4 commit 7be3667

27 files changed

+571
-0
lines changed

% code.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Program to demonstrate string formatting in Python using the '%' operator
2+
3+
# Step 1: Assigning values to variables
4+
name = 'Parth' # The name of the student
5+
course = 'Chemical Engg' # The course the student is enrolled in
6+
age = 19 # The age of the student
7+
8+
# Step 2: Using string formatting to display the values
9+
# The '%s' is used as a placeholder for strings, and '%d' is for integers.
10+
print("name = %s and course = %s and age = %d" % (name, course, age))
11+
12+
# Step 3: Directly formatting values in the string without using variables
13+
# Here, 'Anand', 'Mechanical Engg', and 20 are passed directly into the format placeholders.
14+
print("name = %s and course = %s and age = %d" % ('Anand', 'Mechanical Engg', 20))

(a + b )^2.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Program to verify the algebraic expansion: (a + b)^2 = a^2 + 2ab + b^2
2+
3+
# Input: Taking two integers 'a' and 'b' from the user
4+
a = int(input("Enter value of a: ")) # Asking the user to input the first number
5+
b = int(input("Enter value of b: ")) # Asking the user to input the second number
6+
7+
# Step 1: Calculating the left-hand side of the equation (a + b)^2
8+
lhs = (a + b) ** 2
9+
10+
# Step 2: Calculating the right-hand side of the equation a^2 + 2ab + b^2
11+
rhs = a**2 + 2 * (a * b) + b**2
12+
13+
# Step 3: Checking if the two sides are equal
14+
is_equal = lhs == rhs # This will be True if both sides are equal, otherwise False
15+
16+
# Step 4: Printing the results
17+
print(f"The value of (a + b)^2 is: {lhs}")
18+
print(f"The value of a^2 + 2ab + b^2 is: {rhs}")
19+
print(f"Are both sides equal? {is_equal}") # Will display True if the equation holds
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Program to determine exam eligibility based on attendance percentage
2+
3+
# Step 1: Taking attendance input for three students
4+
# The user enters attendance percentages as integers
5+
a = int(input("Enter attendance % of student A: ")) # Attendance of student A
6+
b = int(input("Enter attendance % of student B: ")) # Attendance of student B
7+
c = int(input("Enter attendance % of student C: ")) # Attendance of student C
8+
9+
# Step 2: Checking eligibility for student A
10+
# If attendance is 75% or more, the student is eligible
11+
if a >= 75:
12+
print("A is eligible to write the exam!")
13+
else:
14+
print("A is not eligible to write the exam!")
15+
16+
# Step 3: Checking eligibility for student B
17+
if b >= 75:
18+
print("B is eligible to write the exam!")
19+
else:
20+
print("B is not eligible to write the exam!")
21+
22+
# Step 4: Checking eligibility for student C
23+
if c >= 75:
24+
print("C is eligible to write the exam!")
25+
else:
26+
print("C is not eligible to write the exam!")

BMI calculator.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Program to calculate BMI (Body Mass Index)
2+
3+
# Step 1: Input height in meters
4+
# The user is prompted to enter their height as a decimal (e.g., 1.65 meters)
5+
height = input("Enter your height in meters (e.g., 1.65): ")
6+
7+
# Step 2: Input weight in kilograms
8+
# The user is prompted to enter their weight as an integer or decimal (e.g., 72 kg)
9+
weight = input("Enter your weight in kilograms (e.g., 72): ")
10+
11+
# Step 3: Convert the inputs to floating-point numbers
12+
new_height = float(height) # Convert height from string to float
13+
new_weight = float(weight) # Convert weight from string to float
14+
15+
# Step 4: Calculate BMI using the formula: weight / (height^2)
16+
# BMI is cast to an integer for a cleaner output
17+
BMI = int(new_weight / (new_height * new_height))
18+
19+
# Step 5: Print the calculated BMI
20+
print(f"Your BMI is: {BMI}")

Bubble Sort(swapping).py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
A = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
2+
3+
print("Before Sorting:", A)
4+
5+
i = 0
6+
while(i < 9): # Outer loop, iterates through the entire list
7+
j = i + 1
8+
while(j < 10): # Inner loop, compares the current element with the next one
9+
if(A[i] > A[j]): # If current element is greater, swap
10+
print("Swapping", A[i], A[j])
11+
t = A[i] # Swap A[i] and A[j]
12+
A[i] = A[j]
13+
A[j] = t
14+
j = j + 1
15+
i = i + 1
16+
17+
print("After Sorting:", A)

LICENSE .txt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
---
3+
4+
### LICENSE
5+
```text
6+
MIT License
7+
8+
Copyright (c) 2024 Akshint
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in all
18+
copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
SOFTWARE.

Mini calculator.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Taking input for two numbers (a and b) and the operation choice (n)
2+
a = int(input("Enter the value of a:"))
3+
b = int(input("Enter the value of b:"))
4+
n = int(input("Choose your operation:\n1. Addition\n2. Subtraction\n3. Multiplication\n4. Division\n"))
5+
6+
# Checking the operation chosen by the user
7+
if (n == 1):
8+
# If the user chose 1, perform addition
9+
print(a + b)
10+
elif (n == 2):
11+
# If the user chose 2, perform subtraction
12+
print(a - b)
13+
elif (n == 3):
14+
# If the user chose 3, perform multiplication
15+
print(a * b)
16+
elif (n == 4):
17+
# If the user chose 4, perform division
18+
# (Ensure that division by zero is handled in real applications)
19+
print(a / b)
20+
else:
21+
# If the user enters an invalid operation choice
22+
print("Invalid choice! Please choose a valid operation.")

Net Worth Program.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Taking input for Mark's net worth (in dollars)
2+
a = int(input("Enter Mark's net worth: "))
3+
4+
# Check if the net worth is exactly 54.5 billion
5+
if a == 54500000000:
6+
print("That's 54.5 billion!")
7+
# If the net worth is less than 54.5 billion
8+
elif a < 54500000000:
9+
print("That's not much")
10+
# If the net worth is more than 54.5 billion
11+
elif a > 54500000000:
12+
print("I'll make more when I graduate")

Simple Addition.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Assigning values to variables a and b
2+
a = 5 # a is set to 5
3+
b = 6 # b is set to 6
4+
5+
# Adding a and b and printing the result
6+
print(a + b) # This will print the sum of a and b, which is 11

calci pt.2.py

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Calculator Program with various functionalities
2+
3+
# Function to add two numbers
4+
def add(x, y):
5+
return x + y
6+
7+
# Function to subtract two numbers
8+
def sub(x, y):
9+
return x - y
10+
11+
# Function to multiply two numbers
12+
def multi(x, y):
13+
return x * y
14+
15+
# Function to divide two numbers
16+
def div(x, y):
17+
if y == 0: # Prevent division by zero
18+
return "Division by zero is not allowed"
19+
return x / y
20+
21+
# Function to calculate power (x^y)
22+
def power(x, y):
23+
return x ** y
24+
25+
# Function to calculate factorial
26+
def factorial(x):
27+
factorial = 1
28+
if x < 0: # Factorial is not defined for negative numbers
29+
return "Factorial not defined for negative numbers"
30+
elif x == 0: # Factorial of 0 is 1
31+
return 1
32+
else:
33+
for i in range(1, x + 1):
34+
factorial *= i # Multiply each number from 1 to x
35+
return factorial
36+
37+
# Main program loop
38+
while True:
39+
# Display menu options
40+
print("\nMenu:")
41+
print("1. Add")
42+
print("2. Subtract")
43+
print("3. Multiply")
44+
print("4. Divide")
45+
print("5. Power")
46+
print("6. Factorial")
47+
print("7. Exit")
48+
49+
# User input for choice
50+
choice = int(input("Enter your choice (1-7): "))
51+
52+
# Perform the selected operation
53+
if choice == 1:
54+
n1 = int(input("Enter first number (n1): "))
55+
n2 = int(input("Enter second number (n2): "))
56+
print(f"{n1} + {n2} = {add(n1, n2)}")
57+
elif choice == 2:
58+
n1 = int(input("Enter first number (n1): "))
59+
n2 = int(input("Enter second number (n2): "))
60+
print(f"{n1} - {n2} = {sub(n1, n2)}")
61+
elif choice == 3:
62+
n1 = int(input("Enter first number (n1): "))
63+
n2 = int(input("Enter second number (n2): "))
64+
print(f"{n1} * {n2} = {multi(n1, n2)}")
65+
elif choice == 4:
66+
n1 = int(input("Enter first number (n1): "))
67+
n2 = int(input("Enter second number (n2): "))
68+
print(f"{n1} / {n2} = {div(n1, n2)}")
69+
elif choice == 5:
70+
n1 = int(input("Enter base number (n1): "))
71+
n2 = int(input("Enter power (n2): "))
72+
print(f"{n1} ^ {n2} = {power(n1, n2)}")
73+
elif choice == 6:
74+
n1 = int(input("Enter a number (n1): "))
75+
print(f"{n1}! = {factorial(n1)}")
76+
elif choice == 7:
77+
print("Exiting the program. Goodbye!")
78+
break # Exit the loop
79+
else:
80+
print("Invalid choice! Please enter a number between 1 and 7.")

count = 0.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Program to print a message while 'count' satisfies the condition
2+
3+
# Step 1: Take user input for the starting value of count
4+
count = int(input("Enter the starting value of count: "))
5+
6+
# Step 2: Loop to print a message 10 times if count is greater than 10
7+
# The loop runs while count is greater than 10
8+
while count > 10:
9+
print("Maths subject")
10+
count = count - 1 # Decrement count to eventually exit the loop
11+
12+
# Step 3: When the loop condition is no longer true, the else block executes
13+
else:
14+
print("Message printed until count dropped below or equal to 10!")

cricket, badminton, football.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Program to find intersections, differences, unions, and specific group memberships of students playing different sports.
2+
3+
# Input: Students playing cricket
4+
a = int(input("Enter the number of students playing cricket: "))
5+
crick = []
6+
for i in range(a):
7+
a1 = input(f"Enter the name of student {i + 1} playing cricket: ")
8+
crick.append(a1)
9+
10+
# Input: Students playing badminton
11+
b = int(input("Enter the number of students playing badminton: "))
12+
bad = []
13+
for i in range(b):
14+
b1 = input(f"Enter the name of student {i + 1} playing badminton: ")
15+
bad.append(b1)
16+
17+
# Input: Students playing football
18+
c = int(input("Enter the number of students playing football: "))
19+
foot = []
20+
for i in range(c):
21+
c1 = input(f"Enter the name of student {i + 1} playing football: ")
22+
foot.append(c1)
23+
24+
# Function to find intersection (common students between two lists)
25+
def inter(lst1, lst2):
26+
res1 = []
27+
for i in lst1:
28+
if i in lst2: # Check if a student is in both lists
29+
res1.append(i)
30+
print("\nStudents playing both cricket and badminton:", res1)
31+
return res1
32+
33+
# Function to find the difference (students in lst1 but not in lst2)
34+
def diff(lst1, lst2):
35+
res2 = []
36+
for i in lst1:
37+
if i not in lst2: # Check if a student is in lst1 but not in lst2
38+
res2.append(i)
39+
print("\nStudents playing cricket but not badminton:", res2)
40+
return res2
41+
42+
# Function to find the union (all unique students from two lists)
43+
def union(lst1, lst2):
44+
res3 = lst1.copy() # Start with all students in lst1
45+
for i in lst2:
46+
if i not in lst1: # Add only those students not already in lst1
47+
res3.append(i)
48+
print("\nUnion of students playing cricket and badminton:", res3)
49+
return res3
50+
51+
# Function to find students playing only cricket and football but not badminton
52+
def block(lst1, lst2, lst3):
53+
res4 = []
54+
for i in lst1:
55+
if i in lst3 and i not in lst2: # Check if a student is in cricket and football but not badminton
56+
res4.append(i)
57+
print("\nStudents playing only cricket and football but not badminton:", res4)
58+
return res4
59+
60+
# Call the functions and display results
61+
inter(crick, bad)
62+
diff(crick, bad)
63+
union(crick, bad)
64+
block(crick, bad, foot)

even or odd.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Program to check whether a number is even or odd.
2+
3+
# Step 1: Take input from the user for the number
4+
n = int(input("Enter the number: "))
5+
6+
# Step 2: Check if the number is divisible by 2 (even) or not (odd)
7+
if (n % 2 == 0): # If the remainder when divided by 2 is 0, it's even
8+
print("Even") # Output: 'Even' if the condition is true
9+
else:
10+
print("Odd") # Output: 'Odd' if the condition is false

factorial.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Program to calculate the factorial of a number.
2+
3+
# Step 1: Take input from the user for the number
4+
num = int(input("Enter the value: "))
5+
6+
# Step 2: Initialize the factorial variable to 1
7+
factorial = 1
8+
9+
# Step 3: Check if the number is negative (factorial is not valid for negative numbers)
10+
if (num < 0):
11+
print("Not Valid") # Factorial is not defined for negative numbers
12+
13+
# Step 4: If the number is 0 or 1, return factorial as 1
14+
elif (num == 0 or num == 1):
15+
print("Factorial of", num, "is 1") # The factorial of 0 and 1 is always 1
16+
17+
# Step 5: For numbers greater than 1, calculate the factorial using a loop
18+
else:
19+
for i in range(1, num + 1): # Loop from 1 to num (inclusive)
20+
factorial = factorial * i # Multiply the current value of factorial by the current number in the loop
21+
print("Factorial of", num, "is", factorial) # Output the calculated factorial

finding the greatest no

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Program to find the greatest of three numbers.
2+
3+
# Step 1: Take input for the three numbers
4+
n1 = int(input("Enter the 1st value: "))
5+
n2 = int(input("Enter the 2nd value: "))
6+
n3 = int(input("Enter the 3rd value: "))
7+
8+
# Step 2: Compare the first number (n1) with the other two numbers
9+
if (n1 > n2): # Check if n1 is greater than n2
10+
if (n1 > n3): # If n1 is also greater than n3, then n1 is the greatest
11+
print("n1 is greater!")
12+
else: # If n1 is not greater than n3, then n3 is the greatest
13+
print("n3 is greater!")
14+
elif (n2 > n3): # If n1 is not greater than n2, compare n2 and n3
15+
print("n2 is greater!") # If n2 is greater than n3, n2 is the greatest
16+
else: # If n2 is not greater than n3, then n3 is the greatest
17+
print("n3 is greater!")

i=1 loop.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Program to print numbers from 1 to 10 using a while loop.
2+
3+
# Step 1: Initialize the variable i with 1
4+
i = 1
5+
6+
# Step 2: Start a while loop that runs as long as i is less than or equal to 10
7+
while (i <= 10):
8+
# Step 3: Print the current value of i
9+
print(i)
10+
11+
# Step 4: Increment the value of i by 1 after each iteration
12+
i = i + 1

0 commit comments

Comments
 (0)