Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions python_problem/Intermediate_problem_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#Problem-01 : Longest Word in a Sentence

text="Machine learning is fascinating"

list_text=text.split(" ")
print(list_text)
max_length=0
result=""
for i in list_text:
if len(i)>max_length:
max_length=len(i)
result=i


print(result)



15 changes: 15 additions & 0 deletions python_problem/Intermediate_problem_02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#Problem-2: Group Anagrams Together
input_list=["bat", "tab", "cat", "act"]
dictionary={}
li=[]
for words in input_list:
key="".join(sorted(words))

if key not in dictionary:
dictionary[key]=[]
dictionary[key].append(words)


print(list(dictionary.values()))


12 changes: 12 additions & 0 deletions python_problem/beginner_pro_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#Problem-1: Reverse a String Without Slicing

input_string="bongodev"
result_string=""

for i in range(len(input_string)-1,-1,-1):
result_string+=input_string[i]


print(result_string)


10 changes: 10 additions & 0 deletions python_problem/beginner_pro_02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#Problem-2: Count Vowels in a Sentence

input_string="Data Science is awesome"
lower_case_string=input_string.lower()
cnt=0
for i in lower_case_string:
if i=='a' or i=='e' or i=='i' or i=='o' or i=='u':
cnt+=1

print(cnt)
15 changes: 15 additions & 0 deletions python_problem/beginner_pro_03.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#Problem-3: Find Duplicates in a List
inp_lis=["ai", "ml", "python", "ml", "dl", "ai"]

imd_lis=[]
res_lis=[]
cnt=0
for i in inp_lis:
if i not in imd_lis:
imd_lis.append(i)
else:
res_lis.append(i)

print(res_lis)


7 changes: 7 additions & 0 deletions python_problem/beginner_pro_04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#Problem-4: Check if a Word is a Palindrome

inp_str="Madam".lower()
if inp_str==inp_str[::-1]:
print("True")
else:
print("False")
18 changes: 18 additions & 0 deletions python_problem/beginner_pro_05.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#Problem-5: Flatten a Nested List
lis=[1, [2, 3], [4, [5]]]
new_lis=[]
var=5
def single_lis(lis):
for i in lis:
if type(var)==type(i):
new_lis.append(i)
else:
single_lis(i)


for i in lis:
single_lis(lis)

print(list(set(new_lis)))


4 changes: 4 additions & 0 deletions python_problem/beginner_pro_06.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Problem-6: Capitalize First Letter of Each Word
inp_str="python for web developers"
result=inp_str.title()
print(result)
8 changes: 8 additions & 0 deletions python_problem/beginner_pro_07.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#Problem-7: Find Missing Number in a Sequence

inp_lis=[1, 2, 4, 5]

for i in range(len(inp_lis)):
if inp_lis[i]!=i+1:
print(f"missing value = {i+1}")
break
7 changes: 7 additions & 0 deletions python_problem/beginner_pro_08.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
inp=5
def calculate_factorial(inp):
if inp==0 or inp==1:
return 1
return inp*calculate_factorial(inp-1)

print(calculate_factorial(inp))
8 changes: 8 additions & 0 deletions python_problem/beginner_pro_09.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#Problem-9: Sum of Digits of an Integer
inp=9875
st=str(9875)
summ=0
for i in st:
summ+=int(i)

print(summ)
11 changes: 11 additions & 0 deletions python_problem/beginner_pro_10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Check if a Number is Prime
import math
inp=33
fl=True
ii=int(math.sqrt(inp))
for i in range(2,ii):
if inp%i==0:
fl=False

if fl:print("Prime Number")
else:print("Not prime number")
3 changes: 3 additions & 0 deletions python_problem/problem_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#write a program to find the length of the variable name
name="Hello there"
print(len(name))
3 changes: 3 additions & 0 deletions python_problem/problem_02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#write a program to find the type of the variable name
name="Hello there"
print(type(name))
9 changes: 9 additions & 0 deletions python_problem/problem_03.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#Write a function that takes 2 numbers as arguments (age of two brothers) and find who is elder
def elder_find(age1,age2):
if age1>age2:
print("Brother 01 is elder")
else:
print("Brother 2 is elder")


elder_find(50,70)
5 changes: 5 additions & 0 deletions python_problem/problem_04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Write a program to find the index of 7
numbers=[3, 5, 1, 9, 7, 2, 8 ]
for i in range(1,len(numbers)):
if numbers[i]==7:
print(f"The index of 7 = {i}")
4 changes: 4 additions & 0 deletions python_problem/problem_05.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Write a program to sort the numbers in Ascending order
numbers=[3, 5, 1, 9, 7, 2, 8 ]
numbers.sort()
print(numbers)
10 changes: 10 additions & 0 deletions python_problem/problem_06.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#Write a function named "isLandscape" that takes 2 numbers (image width and height) as arguments and the function
# returns Landscape if the image width has a higher value than height. Returns Portrait otherwise

def isLandscape(width,height):
if width>height:
return "Landscape"
else:
return "Portrait"

print(isLandscape(600,500))
16 changes: 16 additions & 0 deletions python_problem/problem_07.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#Write a function that takes 1 number as argument. The function should return “Fizz” if the number is divisible by 3,
# the function should return “Buzz” if the number is divisible by 5, the function should return “FizzBuzz” if the number
# is divisible by both 5 and 3, otherwise return “Not a Fizz-buzz number”

def calculate(num):
if num%3==0 and num%5==0:
return "FizzBuzz"
elif num%5==0:
return "Buzz"
elif num%3==0:
return "Fizz"
else:
return "Not a Fizz-buzz number"


print(calculate(20))
14 changes: 14 additions & 0 deletions python_problem/problem_08.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#Write a function that takes a number 1 to 9 from the user input (use input function inside a function). Store a number
# in a variable (let’s assume 6). If the input value is less than the variable, print (your guess is almost there), if
# the input value is greater than the variable, print - your guess is higher, if the input value and variable are equals,
# print - Your Guess Is Correct!

guess_number=int(input("Guess a number(from 1 to 100) = "))
variable_number=60

if guess_number==variable_number:
print("Your Guess Is Correct!")
elif guess_number<variable_number:
print("your guess is almost there")
else:
print("your guess is higher")
8 changes: 8 additions & 0 deletions python_problem/problem_09.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#Find if 6 is available in the list

my_list = [4, 8, 7, 4,3,6,2,1,9]

if 6 in my_list:
print(f"{6} is in the list")
else:
print(f"{6} is not in the list")
11 changes: 11 additions & 0 deletions python_problem/problem_10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#The list below is the collection of the ages of people from a village. Clean up the data and store only numbers in
# another list.

data_list = [13, 24, 'Karim', {'name': 'guru'}, 45, 17]
new_data_list=[]
var=10
for i in data_list:
if type(var)== type(i):
new_data_list.append(i)

print(new_data_list)
25 changes: 25 additions & 0 deletions python_problem/problem_11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#Find the most frequent character in the paragraph
rhyme="Twinkle, twinkle, little star. How I wonder what you are!"
new_dictionary={}

for i in rhyme:
if i in new_dictionary:
new_dictionary[i]+=1
else:
new_dictionary[i]=1

print(new_dictionary)
min_value=0
letter=""
for i in new_dictionary:
if new_dictionary[i]>min_value:
min_value=new_dictionary[i]
letter=i




print(f"most frequent character {letter}:{min_value}")



13 changes: 13 additions & 0 deletions python_problem/problem_12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Find the common items between the lists and make SUM of the new list items which are common between the lists.
list1 = [3, 5, 7, 4, 8, 8]

list2 = [4, 9, 8, 7, 1,1, 13]

common_list=[]
for i in list1:
if i in list2:
common_list.append(i)



print(list(set(common_list)))
13 changes: 13 additions & 0 deletions python_problem/problem_13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#Compare the two dictionaries and find the common items based on KEYs of the dictionaries

dict1 = {'age': 13, 'id': 12, 'address': 'Banani', 'course': 'Python'}

dict2 = {'address': 'Rupnagar', 'id': 25, 'course': 'MERN'}
new_list=[]

for i in dict2:
if i in dict1:
new_list.append(dict1[i])
new_list.append(dict2[i])

print(new_list)
7 changes: 7 additions & 0 deletions python_problem/problem_14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#Sort the list in DESCENDING order and find the subtraction of maximum and minimum numbers.
list_1 = [4, 9, 8, 7, 5, 2, 13]

list_1.sort(reverse=True)
print(list_1)
result=list_1[0]-list_1[-1]
print(result)
31 changes: 31 additions & 0 deletions python_problem/problem_15.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#Write conditional statements to identify the student’s average marks. If any subject’s mark is less than 40, you should print FAILED instead of making average marks
student_1 = [40, 35, 70, 90, 56]

student_2 = [57, 35, 80, 98, 46]

sum1=0
f1=False
sum2=0
f2=False

failed_mark=40
for i in range(len(student_2)):
if student_1[i]>=failed_mark:
sum1+=student_1[i]
else:
f1=True

if student_2[i]>=failed_mark:
sum2+=student_2[i]
else:
f2=True
if f1:print("Student 1 is failed")
else:print(f"Student 1 avarage mark = {sum1/len(student_1)}")

if f2:print("Student 2 is failed")
else:print(f"Student 2 avarage mark = {sum2/len(student_2)}")