diff --git a/python_problem/Intermediate_problem_01.py b/python_problem/Intermediate_problem_01.py new file mode 100644 index 0000000..d49e67b --- /dev/null +++ b/python_problem/Intermediate_problem_01.py @@ -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) + + + diff --git a/python_problem/Intermediate_problem_02.py b/python_problem/Intermediate_problem_02.py new file mode 100644 index 0000000..7244895 --- /dev/null +++ b/python_problem/Intermediate_problem_02.py @@ -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())) + + diff --git a/python_problem/beginner_pro_01.py b/python_problem/beginner_pro_01.py new file mode 100644 index 0000000..236f529 --- /dev/null +++ b/python_problem/beginner_pro_01.py @@ -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) + + diff --git a/python_problem/beginner_pro_02.py b/python_problem/beginner_pro_02.py new file mode 100644 index 0000000..5354adf --- /dev/null +++ b/python_problem/beginner_pro_02.py @@ -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) diff --git a/python_problem/beginner_pro_03.py b/python_problem/beginner_pro_03.py new file mode 100644 index 0000000..ec2c165 --- /dev/null +++ b/python_problem/beginner_pro_03.py @@ -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) + + diff --git a/python_problem/beginner_pro_04.py b/python_problem/beginner_pro_04.py new file mode 100644 index 0000000..e6c5ef0 --- /dev/null +++ b/python_problem/beginner_pro_04.py @@ -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") \ No newline at end of file diff --git a/python_problem/beginner_pro_05.py b/python_problem/beginner_pro_05.py new file mode 100644 index 0000000..618776d --- /dev/null +++ b/python_problem/beginner_pro_05.py @@ -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))) + + diff --git a/python_problem/beginner_pro_06.py b/python_problem/beginner_pro_06.py new file mode 100644 index 0000000..34478b6 --- /dev/null +++ b/python_problem/beginner_pro_06.py @@ -0,0 +1,4 @@ +#Problem-6: Capitalize First Letter of Each Word +inp_str="python for web developers" +result=inp_str.title() +print(result) \ No newline at end of file diff --git a/python_problem/beginner_pro_07.py b/python_problem/beginner_pro_07.py new file mode 100644 index 0000000..64cec7f --- /dev/null +++ b/python_problem/beginner_pro_07.py @@ -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 \ No newline at end of file diff --git a/python_problem/beginner_pro_08.py b/python_problem/beginner_pro_08.py new file mode 100644 index 0000000..c3afb22 --- /dev/null +++ b/python_problem/beginner_pro_08.py @@ -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)) \ No newline at end of file diff --git a/python_problem/beginner_pro_09.py b/python_problem/beginner_pro_09.py new file mode 100644 index 0000000..5795dc9 --- /dev/null +++ b/python_problem/beginner_pro_09.py @@ -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) diff --git a/python_problem/beginner_pro_10.py b/python_problem/beginner_pro_10.py new file mode 100644 index 0000000..a80f389 --- /dev/null +++ b/python_problem/beginner_pro_10.py @@ -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") \ No newline at end of file diff --git a/python_problem/problem_01.py b/python_problem/problem_01.py new file mode 100644 index 0000000..5f87f4d --- /dev/null +++ b/python_problem/problem_01.py @@ -0,0 +1,3 @@ +#write a program to find the length of the variable name +name="Hello there" +print(len(name)) \ No newline at end of file diff --git a/python_problem/problem_02.py b/python_problem/problem_02.py new file mode 100644 index 0000000..f608836 --- /dev/null +++ b/python_problem/problem_02.py @@ -0,0 +1,3 @@ +#write a program to find the type of the variable name +name="Hello there" +print(type(name)) \ No newline at end of file diff --git a/python_problem/problem_03.py b/python_problem/problem_03.py new file mode 100644 index 0000000..203dec2 --- /dev/null +++ b/python_problem/problem_03.py @@ -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) \ No newline at end of file diff --git a/python_problem/problem_04.py b/python_problem/problem_04.py new file mode 100644 index 0000000..9dacf0d --- /dev/null +++ b/python_problem/problem_04.py @@ -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}") \ No newline at end of file diff --git a/python_problem/problem_05.py b/python_problem/problem_05.py new file mode 100644 index 0000000..3627586 --- /dev/null +++ b/python_problem/problem_05.py @@ -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) \ No newline at end of file diff --git a/python_problem/problem_06.py b/python_problem/problem_06.py new file mode 100644 index 0000000..4198e91 --- /dev/null +++ b/python_problem/problem_06.py @@ -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)) \ No newline at end of file diff --git a/python_problem/problem_07.py b/python_problem/problem_07.py new file mode 100644 index 0000000..a396926 --- /dev/null +++ b/python_problem/problem_07.py @@ -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)) \ No newline at end of file diff --git a/python_problem/problem_08.py b/python_problem/problem_08.py new file mode 100644 index 0000000..71a39b4 --- /dev/null +++ b/python_problem/problem_08.py @@ -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_numbermin_value: + min_value=new_dictionary[i] + letter=i + + + + +print(f"most frequent character {letter}:{min_value}") + + + diff --git a/python_problem/problem_12.py b/python_problem/problem_12.py new file mode 100644 index 0000000..7fb8e9d --- /dev/null +++ b/python_problem/problem_12.py @@ -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))) diff --git a/python_problem/problem_13.py b/python_problem/problem_13.py new file mode 100644 index 0000000..cdff903 --- /dev/null +++ b/python_problem/problem_13.py @@ -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) diff --git a/python_problem/problem_14.py b/python_problem/problem_14.py new file mode 100644 index 0000000..be6c3c7 --- /dev/null +++ b/python_problem/problem_14.py @@ -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) \ No newline at end of file diff --git a/python_problem/problem_15.py b/python_problem/problem_15.py new file mode 100644 index 0000000..64ced53 --- /dev/null +++ b/python_problem/problem_15.py @@ -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)}") + + + + +