8000 days 6 · chandantech56/python-class@68b2fab · GitHub
[go: up one dir, main page]

Skip to content

Commit 68b2fab

Browse files
committed
days 6
1 parent dae349a commit 68b2fab

File tree

5 files changed

+160
-2
lines changed

5 files changed

+160
-2
lines changed

function_practice/calculator.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Simple Python Calculator
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 subtract(x, y):
9+
return x - y
10+
11+
# Function to multiply two numbers
12+
def multiply(x, y):
13+
return x * y
14+
15+
# Function to divide two numbers
16+
def divide(x, y):
17+
if y != 0:
18+
return x / y
19+
else:
20+
return "Error! Division by zero."
21+
22+
# Displaying the menu
23+
def display_menu():
24+
print("Select operation:")
25+
print("1. Add")
26+
print("2. Subtract")
27+
print("3. Multiply")
28+
print("4. Divide")
29+
print("5. Exit")
30+
31+
# Main program
32+
def main():
33+
while True:
34+
display_menu()
35+
36+
# Taking user input for operation
37+
choice = input("Enter choice (1/2/3/4/5): ")
38+
39+
# Check if the user chose to exit
40+
if choice == '5':
41+
print("Exiting the calculator. Goodbye!")
42+
break
43+
44+
# Ensure the input is valid
45+
if choice in ('1', '2', '3', '4'):
46+
# Taking user input for the numbers
47+
num1 = float(input("Enter first number: "))
48+
num2 = float(input("Enter second number: "))
49+
50+
# Perform the chosen operation
51+
if choice == '1':
52+
print(f"The result is: {add(num1, num2)}\n")
53+
elif choice == '2':
54+
print(f"The result is: {subtract(num1, num2)}\n")
55+
elif choice == '3':
56+
print(f"The result is: {multiply(num1, num2)}\n")
57+
elif choice == '4':
58+
print(f"The result is: {divide(num1, num2)}\n")
59+
else:
60+
print("Invalid input! Please select a valid operation.\n")
61+
62+
if __name__ == "__main__":
63+
main()

function_practice/function.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def calc_sum(a,b):
2+
return a+b
3+
sum = calc_sum(10,20)
4+
print(sum)
5+
6+
sum = calc_sum(35,30)
7+
print(sum)
8+
9+
def avr_number(a,b,c):
10+
sum = a+b+c
11+
avr = sum/3
12+
return avr
13+
avr = avr_number(10,20,5)
14+
print(avr)
15+
16+
# cities = ["delhi","bangalore", "hyderabad", "mumbai"]
17+
18+
n = 1
19+
for i in range(1, n+1):
20+
n*=1
21+
print(5)

python_class5/class5.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,20 @@
1717
print(my_list)
1818
print(type(my_list))
1919

20-
#nested data types: [0,2]
20+
#nested data types: [2]
2121
L = ['a', 'b' ,['cc','dd',['eee','fff']],'g','h']
2222
print(L)
2323
print(L[2])
2424
print(L[2][0])
2525
print(L[2][2])
26-
26+
print(L[3])
2727
#negative index data
2828
# Negative indexing means start from the end
2929
# -1 refers to the last item, -2 refers to the second last item etc.
3030
thislist = ["apple", "banana", "cherry"]
3131
print(thislist[-1])
3232

33+
# slicing in list
3334
#Negative indexing means starting from the end of the list.
3435
#This example returns the items from index -4 (included) to index -1 (excluded)
3536
#Remember that the last item has the index -1,

python_class6/assignment.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
number= [10,20,5,8,9,7,11]
2+
number[1]=30
3+
print(number)
4+
5+
number[2:3]= 15,16
6+
print(number)
7+
number.append(12)
8+
print(number)
9+
10+
number.extend([13,14,15,16])
11+
print(number)
12+
13+
number.insert(1,15)
14+
print(number)
15+
16+
number.remove(10)
17+
print(number)
18+
19+
number.pop(2)
20+
print(number)
21+
#delete function
22+
del number[2]
23+
print(number)
24+
cities= ["delhi","hydrabad","bangalore","pune","goa"]
25+
del cities[3]
26+
print(cities)

python_class6/class6.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
even= [2,4,6,8,10]
2+
even[3]= 5
3+
print(even)
4+
5+
even= [3,5,7,9,11]
6+
even[4]=10
7+
print(even)
8+
9+
odd= [3,5,7,9,11]
10+
odd[2:4]= [2,4,8]
11+
print(odd)
12+
13+
odd = [1,3,5]
14+
odd.append(6)
15+
print(odd)
16+
17+
#odd.apend(2,9): there are error show. bcz only one value put in value in append method.
18+
19+
odd.extend([9,11,13]) #multiple value added in extend methods
20+
print(odd)
21+
22+
odd = [1,9]
23+
odd.insert(1,3) #print index before
24+
print(odd)
25+
odd[2:2]=[5,7]
26+
print(odd)
27+
# concatination and repeting
28+
odd= [1,3,5]
29+
print(odd+[9,7,5])
30+
print(["re"]*3)
31+
32+
#deleting list items
33+
my_list = ["p","r", "o","y","t"]
34+
del my_list[2]
35+
print(my_list)
36+
del my_list[1:3]
37+
print(my_list)
38+
del my_list
39+
# print(my_list) #deleting all variable and values so showing error
40+
41+
my_list = ["p","r", "o","y","t"]
42+
my_list.remove("r") #remove method : remove at the given particular values
43+
print(my_list)
44+
my_list.pop() #pop method: remove last list value
45+
print(my_list)
46+
my_list.pop(1) # remove index wise in list
47+
print(my_list)

0 commit comments

Comments
 (0)
0