Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
bdf1385
Answer for question 26
jerald-jacob Oct 1, 2021
18b9a53
Merge pull request #39 from Marian-MCA/jerald-jacob-patch-1
jerald-jacob Oct 1, 2021
65d91e1
Merge pull request #40 from Marian-MCA/jerald-jacob-patch-2
jerald-jacob Oct 1, 2021
7914bd6
Create qn_26.txt
jerald-jacob Oct 5, 2021
a21afa8
Create qn_26.txt
jerald-jacob Oct 5, 2021
87b92f7
Merge pull request #41 from Marian-MCA/jerald-jacob-patch-1
jerald-jacob Oct 5, 2021
e8dcfee
Merge pull request #42 from Marian-MCA/jerald-jacob-patch-3
jerald-jacob Oct 5, 2021
6490e02
Create qn_27.txt
Liby-joseph Oct 7, 2021
f462fbf
Merge pull request #43 from Liby-joseph/patch-5
jerald-jacob Oct 7, 2021
65d6137
Create Ans_qn_27.txt
Liby-joseph Oct 7, 2021
80caae2
Merge pull request #44 from Liby-joseph/patch-6
jerald-jacob Oct 7, 2021
dc372c7
Create qn_28.txt
Liby-joseph Oct 7, 2021
525993f
Merge pull request #45 from Liby-joseph/patch-7
jerald-jacob Oct 7, 2021
2dcce02
Update Ans_qn_27.txt
jerald-jacob Oct 7, 2021
55ecebf
Update Ans_qn_27.txt
jerald-jacob Oct 7, 2021
42ab873
Merge pull request #46 from Marian-MCA/jerald-jacob-patch-4
jerald-jacob Oct 7, 2021
df97453
Create qn_29.txt
Liby-joseph Oct 7, 2021
9bfc7a7
Merge pull request #47 from Liby-joseph/patch-8
jerald-jacob Oct 7, 2021
f346a26
Update qn_29.txt
jerald-jacob Oct 7, 2021
431260e
Merge pull request #48 from Marian-MCA/jerald-jacob-patch-5
jerald-jacob Oct 7, 2021
b0532c0
Create Ans_qn_29.txt
Liby-joseph Oct 7, 2021
0a63e2b
Merge pull request #49 from Liby-joseph/patch-9
jerald-jacob Oct 7, 2021
a4420be
Create qn_30.txt
Liby-joseph Oct 7, 2021
dcffdbf
Merge pull request #50 from Liby-joseph/patch-10
jerald-jacob Oct 7, 2021
577f90e
Created a README.md file
Saurabh27096 Oct 7, 2021
d81ba7f
Update qn_6.txt
Saurabh27096 Oct 7, 2021
c2ec875
Merge pull request #51 from Saurabh27096/master
ajilraju Oct 7, 2021
88c220e
Create question_29
jerald-jacob Oct 6, 2022
48b7a67
Merge pull request #52 from Marian-MCA/jerald-jacob-patch-6
ajilraju Oct 6, 2022
3e0fcf2
added qn 28 and answer
inv-vince Oct 6, 2022
a7fe6fc
Merge pull request #53 from vincecyriac/master
ajilraju Oct 6, 2022
66fc034
Merge pull request #7 from Marian-MCA/master
ajilraju Oct 6, 2022
d1243bd
moved all old things to new archives folder
ajilraju Oct 6, 2022
588ff5b
changed README.md for new platform
ajilraju Oct 6, 2022
0a0e58e
added new 1 problem
ajilraju Oct 6, 2022
62dcceb
Merge branch 'Marian-MCA:master' into master
ajilraju Oct 6, 2022
a965e6f
added solution to problem one
ajilraju Oct 6, 2022
91bc0fa
Merge pull request #54 from ajilraju/master
ajilraju Oct 6, 2022
e8d1a69
Create 2_problem.md
jerald-jacob Oct 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
<h1 align="center"> Python practical zone </h1>
<h1 align="center"> Python practical zone, not only for Python </h1>

<p align="center">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Python-logo-notext.svg/2000px-Python-logo-notext.svg.png" width="200" height="200"/>
</p>

<h2 align="center">Project status <img src="https://travis-ci.org/ajilraju/python-practical-zone.svg?branch=master"/></h2>

<p align="center">
Problem-driven and individualized -
Fun -
Safe from failure -
Group engagement
</p>
<p>Python is a widely used high-level, general-purpose, interpreted, dynamic programming language. Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than possible in languages such as C++ or Java.

Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive standard library

The best way we learn anything is by practice and exercise questions. We have started this section for those (beginner to intermediate) who are familiar with Python.

Hope, these exercises help you to improve your Python coding skills. Currently, following sections are available, we are working hard to add more exercises .... Happy Coding!</p>
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
Sample value of n is 5

Expected Result : 615

n=int (input("Enter a number")
print(n+(n*n)+(n*n*n)).
22 changes: 22 additions & 0 deletions archives/Basic-Part-1/questions/qn_26.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Calculate the multiplication and sum of two numbers

Given two integer numbers return their product only if the product is greater than 1000, else return their sum.

Given 1:

number1 = 20
number2 = 30

Expected Output:

The result is 600

Given 2:

number1 = 40
number2 = 30

Expected Output:

The result is 70

8 changes: 8 additions & 0 deletions archives/Basic-Part-1/questions/qn_27.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
What is the output of the following code?


first = [1, 2, 3, 4, 5]
second = first
second.append(6)
print(first)
print(second)
5 changes: 5 additions & 0 deletions archives/Basic-Part-1/questions/qn_28.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Python List Slicing Using Negative Indexing
What is the output of the following Python code snippet?

a = [1,2,3,4,5,6,7,8,9]
print(a[-1:-5])
11 changes: 11 additions & 0 deletions archives/Basic-Part-1/questions/qn_29.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Tuple and String Type
Here is the code snippet. You have to find the type of the given three objects.

A = ("Python" , "Java")
print(type(A))

B = ("Python", )
print(type(B))

C = ("Python")
print(type(C))
18 changes: 18 additions & 0 deletions archives/Basic-Part-1/questions/qn_30.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Differentiating List extend() Method
What is the output of print statements 1 and 2 in the following code snippet?.

listA = [1, 2, 3]
def funcA(listA):
listA = listA * 2
return None

funcA(listA)
print(listA) # print Statement 1

listB = [1, 2, 3]
def funcB(listB):
listB=listB.extend([1, 2, 3])
return None

funcB(listB)
print(listB) # print Statement 2
26 changes: 26 additions & 0 deletions archives/Basic-Part-1/source-code/Ans_qn_27.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5, 6]

Explanation:

You are appending a new element to the second list. Then, why do you see a new element even in the first list?

This is really confusing.

Here is actual fact.

The code line “second = first ” creates the shallow copy of the list. It means there will be a single list in memory. The first and second variables are pointed to the same list.It does not maintain two separate lists, but only one. If you modify using one list variable, it will make the changes in the list for both variables.
If you want to maintain two separate lists for two list objects, you need to create a deep copy of the list. Refer a shallow and deep copy You can also print the identity of the objects (first and second) using id() inbuilt function.

Python

first = [1, 2, 3, 4, 5]
second = first
print(id(second))
print(id(first))


Output:

140683246201032
140683246201032
16 changes: 16 additions & 0 deletions archives/Basic-Part-1/source-code/Ans_qn_29.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Output:

<class 'tuple'>
<class 'tuple'>
<class 'str'>
Explanation:

These objects are classified into different data types.

tuple- It stores the element just like an array. (It is slightly different from list.)
str- it is a string that is a set of characters.
Let’s take a scenario one by one.

Object ‘A’ is a tuple. It’s very clear from its syntax.
Object ‘B’ is again tuple. Despite having only one string, it has comma ‘,’ after the string. So it can not be a string.
Object ‘C’ is a string. It has only one string though it has enclosed inside the brackets. So, Python considers it as a string.
17 changes: 17 additions & 0 deletions archives/Basic-Part-1/source-code/qn_26.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
def multiplication_or_sum(num1, num2):
# calculate product of two number
product = num1 * num2
# check if product is less then 1000
if product <= 1000:
return product
else:
# product is greater than 1000 calculate sum
return num1 + num2

# first condition
result = multiplication_or_sum(20, 30)
print("The result is", result)

# Second condition
result = multiplication_or_sum(40, 30)
print("The result is", result)
11 changes: 11 additions & 0 deletions archives/Basic-Part-2/questions/qn_28.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
You are in charge of the cake for a child's birthday. You have decided the cake will have one candle for each year of their total age. They will only be able to blow out the tallest of the candles. Count how many candles are tallest.

Example
candles = [4,4,1,3]
The maximum height candles are 4 units high. There are 2 of them, so return 2.

birthdayCakeCandles has the following parameter(s):
1. int candles[n]: the candle heights

Returns:
int: the number of candles that are tallest
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
Write a Python program to create a lambda function that adds 15 to a given number passed in as an argument, also create a lambda function that multiplies argument x with argument y and print the result.
a = lambda x : x+15
b = lambda x,y : x*y
print(a(5))
print(b(2,3))
25 changes: 25 additions & 0 deletions archives/Basic-Part-2/questions/question_29
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Write a function to find the longest common prefix string amongst an array of strings.

If there is no common prefix, return an empty string "".



Example 1:

Input: strs = ["flower","flow","flight"]
Output: "fl"

Example 2:

Input: strs = ["dog","racecar","car"]
Output: ""
Explanation: There is no common prefix among the input strings.



Constraints:

1 <= strs.length <= 200
0 <= strs[i].length <= 200
strs[i] consists of only lowercase English letters.

15 changes: 15 additions & 0 deletions archives/Basic-Part-2/source-code/qn_26_answer.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
The common built in data types in python are-

Numbers– They include integers, floating point numbers, and complex numbers. eg. 1, 7.9,3+4i

List– An ordered sequence of items is called a list. The elements of a list may belong to different data types. Eg. [5,’market’,2.4]

Tuple– It is also an ordered sequence of elements. Unlike lists , tuples are immutable, which means they can’t be changed. Eg. (3,’tool’,1)

String– A sequence of characters is called a string. They are declared within single or double quotes. Eg. “Sana”, ‘She is going to the market’, etc.

Set– Sets are a collection of unique items that are not in order. Eg. {7,6,8}

Dictionary– A dictionary stores values in key and value pairs where each value can be accessed through its key. The order of items is not important. Eg. {1:’apple’,2:’mango}

Boolean– There are 2 boolean values- True and False.
10 changes: 10 additions & 0 deletions archives/Basic-Part-2/source-code/qn_28.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def birthdayCakeCandles(ar):
c = 0
temp = ar[0]
for i in range(1,len(ar)):
if ar[i] > temp:
temp = ar[i]
for i in range(0,len(ar)):
if ar[i] == temp:
c = c + 1
return c
File renamed without changes.
15 changes: 15 additions & 0 deletions problems/1_problem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Write a function to find the longest common prefix string amongst an array of strings.

If there is no common prefix, return an empty string "".

Example 1:
```
Input: strs = ["flower","flow","flight"]
Output: "fl"
```
Example 2:
```
Input: strs = ["dog","racecar","car"]
Output: ""
Explanation: There is no common prefix among the input strings.
```
17 changes: 17 additions & 0 deletions problems/2_problem.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Write a function to find the longest common prefix string amongst an array of strings.

If there is no common prefix, return an empty string "".



Example 1:

Input: strs = ["flower","flow","flight"]
Output: "fl"

Example 2:

Input: strs = ["dog","racecar","car"]
Output: ""
Explanation: There is no common prefix among the input strings.

43 changes: 43 additions & 0 deletions solutions/1_solution.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"fmt"
"strings"
)

func prefixThere(str []string, pf string) bool {
present := ""
for _, ss := range str {
if !strings.HasPrefix(ss, pf) {
present += "n"
}
}
if strings.Contains(present, "n") {
return false
}
return true
}

func longestCommonPrefix(strs []string) string {

longPrefix := ""
firstString := strs[0]
restOfString := strs[1:]

if len(strs) == 1 {
longPrefix = firstString
} else {
for i := 1; i <= len(firstString); i++ {
prefix := firstString[0:i]
if prefixThere(restOfString, prefix) {
longPrefix = prefix
}
}
}
return longPrefix
}

func main() {
sSlice := []string{"flower", "flow", "flight"}
fmt.Println(longestCommonPrefix(sSlice))
}