Skip to content

Commit 3f25828

Browse files
committed
day1 Pushed File
0 parents  commit 3f25828

10 files changed

Lines changed: 508 additions & 0 deletions

File tree

Array.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
arr = [1,2,3,4,5,5,6,7,8]
2+
3+
# print(arr) This will print the whole array
4+
5+
# print(arr[0]) This will print the first element of the array
6+
7+
# Printting the array using for in loop
8+
# for i in arr:
9+
# print(i)
10+
11+
12+
# Take using defined input of array from the user
13+
# arr = []
14+
# for ind in range(0,10):
15+
# x = int(input("Enter the Elements of the array : "))
16+
# arr.append(x)
17+
18+
# print(arr)
19+
20+
21+
# print the array using for-in loop
22+
23+
# for i in range(0,len(arr)):
24+
# print("The ",i," index element is : ",arr[i])
25+
26+
27+

Array_methods.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Array Methods in Python
2+
3+
arr = [1,2,3,4,5,6,7,8,9,10,10]
4+
5+
# Print the array
6+
print(arr)
7+
8+
# Print Array Element using Index
9+
print(arr[0])
10+
11+
12+
# Append a element in the list
13+
arr.append(100)
14+
print(arr)
15+
16+
17+
# Clear the array
18+
arr.clear()
19+
print(arr)
20+
21+
22+
# Print the count of any Element in the array
23+
x = arr.count(10)
24+
print("The count of the element in arr is : ",x)
25+
26+
27+
# Return the index of a given element
28+
print(arr.index(10))
29+
30+
31+
# Remove one Element from the last of the array
32+
print(arr)
33+
arr.pop()
34+
print(arr)
35+
36+
37+
# remove the first item with specified value
38+
print(arr)
39+
arr.remove(10)
40+
print(arr)
41+
42+
43+
# Reverse the array
44+
print(arr)
45+
arr.reverse()
46+
print(arr)
47+
48+
49+
# Sort The array
50+
print(arr)
51+
arr.sort()
52+
print(arr)
53+
54+
55+
# Print the length of the array
56+
print("The length of the array is : ",len(arr))
57+
58+
59+
# Add element at the specified position
60+
print(arr)
61+
arr.insert(2,17)#Insert 17 at Index 2
62+
print(arr)
63+
64+
65+
# Copy the array
66+
arr2 = arr.copy()
67+
print(arr2)
68+

Introduction.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Introduction to python
2+
3+
'''
4+
What is Python?
5+
Python is a popular programming language. It was created by Guido van Rossum, and released in 1991.
6+
7+
It is used for:
8+
9+
web development (server-side),
10+
software development,
11+
mathematics,
12+
system scripting.
13+
14+
What can Python do?
15+
Python can be used on a server to create web applications.
16+
Python can be used alongside software to create workflows.
17+
Python can connect to database systems. It can also read and modify files.
18+
Python can be used to handle big data and perform complex mathematics.
19+
Python can be used for rapid prototyping, or for production-ready software development.
20+
21+
Why Python?
22+
Python works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc).
23+
Python has a simple syntax similar to the English language.
24+
Python has syntax that allows developers to write programs with fewer lines than some other programming languages.
25+
Python runs on an interpreter system, meaning that code can be executed as soon as it is written. This means that prototyping can be very quick.
26+
Python can be treated in a procedural way, an object-oriented way or a functional way.
27+
Good to know
28+
29+
The most recent major version of Python is Python 3, which we shall be using in this tutorial. However, Python 2, although not being updated with anything other than security updates, is still quite popular.
30+
In this tutorial Python will be written in a text editor. It is possible to write Python in an Integrated Development Environment, such as Thonny, Pycharm, Netbeans or Eclipse which are particularly useful when managing larger collections of Python files.
31+
Python Syntax compared to other programming languages
32+
Python was designed for readability, and has some similarities to the English language with influence from mathematics.
33+
Python uses new lines to complete a command, as opposed to other programming languages which often use semicolons or parentheses.
34+
Python relies on indentation, using whitespace, to define scope; such as the scope of loops, functions and classes. Other programming languages often use curly-brackets for this purpose.
35+
'''
36+
37+
print("Hello This is python first file")

Loops.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Python programming language provides the following types of loops to handle looping requirements. Python provides three ways for executing the loops. While all the ways provide similar basic functionality, they differ in their syntax and condition-checking time.
2+
3+
# 1 -> For Loop
4+
5+
print("\n\n This is Example of While For In Python")
6+
for i in range(0,100):
7+
print(i)
8+
9+
for i in range(0,100,3):#print every 3rd element from 0-99
10+
print(i)
11+
12+
# loops in string
13+
14+
str = "Lokesh Singh"
15+
# Example of for-in Loop in python
16+
for character in str:
17+
print(character)
18+
19+
20+
# 2 -> While Loop
21+
print("\n\n This is Example of While loop In Python")
22+
i = 0
23+
while(i<=10):
24+
print(i)
25+
i = i+1 #Python doesn't support i++

Revise.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# print("This is the assignment file")
2+
3+
# Question - 1 Make a program to add the sum of array Elements
4+
def sum(arr):
5+
add = 0
6+
for i in range(0,len(arr)):
7+
add += arr[i]
8+
9+
print("The sum of array element is : ",add)
10+
11+
arr = [1,2,3,4,5]
12+
sum(arr)
13+
14+
15+
# Question - 2 Make a program to find the largest number in an array
16+
def maximum(array):
17+
print("The maximum element in the array is : ",max(arr))
18+
19+
n = int(input("Enter the size of arr : "))
20+
arr = []
21+
for i in range(0,n):
22+
x = int(input())
23+
arr.append(x)
24+
25+
print(arr)
26+
maximum(arr)
27+
28+
29+
# Question - 3 Make a program to find the smallest number in an array
30+
def minimum(array):
31+
print("The minimum element in the array is : ",min(arr))
32+
33+
n = int(input("Enter the size of arr : "))
34+
arr = []
35+
for i in range(0,n):
36+
x = int(input())
37+
arr.append(x)
38+
39+
print(arr)
40+
minimum(arr)
41+
42+
43+
# Question - 4 Make a program that prints second largest element from the array
44+
def second_Max(arr):
45+
maxi = max(arr)
46+
second_max = min(arr)
47+
for i in range(0,len(arr)):
48+
if(maxi<arr[i]):
49+
second_max = maxi
50+
maxi = arr[i]
51+
else:
52+
if(arr[i]>second_max and arr[i]!=maxi):
53+
second_max = arr[i];
54+
55+
print("Second maximum elements of the array is : ",second_max)
56+
57+
58+
59+
n = int(input("Enter the size of arr : "))
60+
arr = []
61+
for i in range(0,n):
62+
x = int(input())
63+
arr.append(x)
64+
65+
second_Max(arr)
66+
67+
68+
# Question - 5 Make a program that take username as input and that prints the length of the name
69+
def print_len(name):
70+
print("The length of the given string is : ",len(name))
71+
name = input("Enter your name : ")
72+
print_len(name)
73+
74+
75+
# Question - 6 Make a program that take array as input and prints every alternate elements
76+
def print_alternate(array):
77+
print("The alternate elements of the array are : \n")
78+
for i in range(0,len(array),2):
79+
print(array[i])
80+
81+
n = int(input("Enter the size of arr : "))
82+
arr = []
83+
for i in range(0,n):
84+
x = int(input())
85+
arr.append(x)
86+
print_alternate(arr)
87+

function.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Now we are Going to see the function in Python
2+
3+
# Function 1 print "hello"
4+
def print_hello():
5+
print("Hello Everyone")
6+
7+
print_hello()
8+
9+
10+
# Function - 2 Check a number is Even or Odd
11+
def check(num):
12+
if(num%2==0):
13+
print("The Number is Even Number")
14+
else:
15+
print("The given Number is Odd Number")
16+
17+
x = int(input("Enter any Number : "))
18+
check(x)
19+
20+
21+
22+
# Function-3 Check Prime
23+
24+
def check_prime(num):
25+
count = 0
26+
for i in range(1,num+1):
27+
if(num%i==0):
28+
count += 1
29+
if(count==2):
30+
print("The given Number is Prime Number")
31+
else:
32+
print("The given Number is Not Prime Number")
33+
34+
x = int(input("Enter any Number : "))
35+
check_prime(x)
36+
37+
38+
39+
# Function - 4 Print the largest Name Among the array of names
40+
def largest_name(names):
41+
max = names[0]
42+
for i in range(1,len(names)):
43+
if(len(names[i])>len(max)):
44+
max = names[i]
45+
return max
46+
47+
names = ["Rajesh","Ramesh","Raj","Rajesh Kumar"]
48+
print("The largest Name is : ",largest_name(names))
49+
50+
51+
# Function - 5 print the table of a given Number
52+
def table(num):
53+
for i in range(1,11):
54+
print(num,"*",i,"=",num*i)
55+
56+
num = int(input("Enter Any Number for Print their Table : "))
57+
table(num)
58+
59+
60+
61+
# Function - 6 Print the second largest element from the array
62+
63+
# Method - 1
64+
def second_largest(arr):
65+
max = arr[0]
66+
for i in range(1,len(arr)):
67+
if(arr[i]>max):
68+
max = arr[i]
69+
arr.remove(max)
70+
max = arr[0]
71+
for i in range(1,len(arr)):
72+
if(arr[i]>max):
73+
max = arr[i]
74+
return max
75+
76+
# Method -2
77+
def second_largest(arr):
78+
maxi = max(arr)
79+
ans = 0
80+
for i in range(0,len(arr)):
81+
if(arr[i]>maxi):
82+
ans = maxi
83+
maxi = arr[i]
84+
elif(arr[i]>ans and arr[i]!=maxi):
85+
ans = arr[i]
86+
return ans
87+
88+
89+
arr =[1,2,3,4,5,6,7,8,9,10,11,23,456,787,78,87,6]
90+
print(second_largest(arr))

0 commit comments

Comments
 (0)