├── README.md
├── Week 1
├── Challenge Yourself
│ ├── 1.txt
│ ├── 2.txt
│ ├── 3.txt
│ ├── 4.txt
│ └── 5.txt
└── Skill Builder
│ ├── 1.txt
│ ├── 10.txt
│ ├── 11.txt
│ ├── 12.txt
│ ├── 13.txt
│ ├── 14.txt
│ ├── 15.txt
│ ├── 2.txt
│ ├── 3.txt
│ ├── 4.txt
│ ├── 5.txt
│ ├── 6.txt
│ ├── 7.txt
│ ├── 8.txt
│ ├── 9.txt
│ └── temp
├── Week 10
├── Challenge Yourself
│ ├── class_Book.py
│ ├── class_py_solution.py
│ ├── class_sum.py
│ └── readme.md
└── Skill Builder
│ ├── Employee.py
│ ├── calculator.py
│ ├── circle.py
│ ├── class_reverse.py
│ ├── country.py
│ ├── pow_class.py
│ ├── readme.md
│ ├── rectangle.py
│ └── reverse_word_by_word.py
├── Week 11
├── Challenge Yourself
│ ├── MULTILEVEL_INHERITANCE.py
│ ├── Pow.py
│ ├── banking.py
│ └── readme.md
└── Skill Builder
│ ├── Bank_account.py
│ ├── Employee.py
│ ├── Hierarchical_Inheritance.py
│ ├── Hybrid_Inheritance.py
│ ├── Multilevel_Inheritance.py
│ ├── Multiple_inheritance.py
│ ├── SINGLE_INHERITANCE.py
│ ├── circle.py
│ └── readme.md
├── Week 12
├── Challenge Yourself
│ ├── SilverStall.py
│ ├── bill.py
│ ├── class_complex.py
│ └── readme.md
└── Skill Builder
│ ├── Function_Overloading.py
│ ├── GST_Calculation.py
│ ├── METHOD_OVERLOADING.py
│ ├── METHOD_OVERLOADING_compute.py
│ ├── Operator_Overloading-Assignment_Operator.py
│ ├── Operator_Overloading.py
│ ├── Operator_Overloading_Mod.py
│ ├── Printing_object_using_str.py
│ └── readme.md
├── Week 13
├── Challenge Yourself
│ ├── Invalid_Input_format.py
│ ├── Seetha.py
│ ├── ZeroDivisionError.py
│ └── readme.md
└── Skill Builder
│ ├── Division_by_Zero.py
│ ├── Invalid_Input_format.py
│ ├── Valid_Integer.py
│ ├── ZeroDivisionError.py
│ ├── given_number_is_large_or_small.py
│ ├── interactive_calculator.py
│ ├── readme.md
│ ├── reciprocal.py
│ └── sum_of_the_N_values.py
├── Week 14
├── Challenge Yourself
│ ├── area_million_sqkm.py
│ ├── display_all_the_employee_names.py
│ ├── display_the_dependents_details.py
│ └── readme.md
└── Skill Builder
│ ├── SQL_version.py
│ ├── Salesman.py
│ ├── Salesman_commission.py
│ ├── Speciality.py
│ ├── display_product_name.py
│ ├── list_of_doctors.py
│ ├── number_of_doctors.py
│ ├── readme.md
│ └── salesmen_firstname.py
├── Week 2
├── Challenge Yourself
│ ├── Lucky Gifts.txt
│ ├── Pranav and Change.txt
│ ├── Talent Show.txt
│ ├── Total Expenses for the Event.txt
│ ├── Trade Fair.txt
│ └── sample.txt
└── Skill Builder
│ ├── Given 2 numbers N,K print the number after performing right shift 'K' times of number N..txt
│ ├── bala chocolate.txt
│ ├── distance between 2 points.txt
│ ├── event.txt
│ ├── exchange 2 niumber.txt
│ ├── kabali ninja.txt
│ ├── print sep value 3-4.txt
│ ├── sample.txt
│ ├── shuffle cards.txt
│ └── vikram.txt
├── Week 3
├── Challenge Yourself
│ ├── Fair_Francis.py
│ ├── Inverted_Hollow_Pyramid.py
│ ├── Lucky_Cards.py
│ ├── Math_Challenge.py
│ ├── Peter_and_Casino.py
│ └── readme.md
└── Skill Builder
│ ├── Connect_the_ropes.py
│ ├── GCD.py
│ ├── Hollow_Pyramid.py
│ ├── Kids_love_muffins.py
│ ├── Series_1.py
│ ├── Series_3.py
│ ├── candy game.py
│ ├── charity_dinner.py
│ ├── max_of_3_numbers.py
│ ├── ram_cfo.py
│ └── readme.md
├── Week 4
├── Challenge Yourself
│ ├── count_number_of_strings.py
│ ├── readme.md
│ ├── recursion_list_sum.py
│ ├── remove&print_3rd_number_from_list.py
│ ├── remove_element_from_tuple.py
│ └── store_sort_check_tuple.py
└── Skill Builder
│ ├── Given_a_number_N.py
│ ├── find_kth_smallest_element.py
│ ├── intersection_of_2_lists.py
│ ├── print_max_min_length_of_tuple.py
│ ├── print_next_smallest_element_in_tuple.py
│ ├── print_the_tuple.py
│ ├── readme.md
│ ├── remove_duplicate_from_a_list.py
│ ├── sort_tuple_of_tuples_by_2nd_item.py
│ ├── store_positive_values_from_list.py
│ └── store_search_sort_tuple.py
├── Week 5
├── Challenge Yourself
│ ├── append_list.py
│ ├── match_key_values.py
│ ├── pizza_delivery_drones.py
│ ├── ram_shopping_total.py
│ ├── readme.md
│ └── sets_X_and_Y.py
└── Skill builder
│ ├── Generate_set.py
│ ├── Sanjay_and_Rahul.py
│ ├── Stationery_shop.py
│ ├── concatenate_three_dictionaries.py
│ ├── convert_a_set_of_integers.py
│ ├── create_a_set_with_the_positive_integers.py
│ ├── get_the_top_three_items.py
│ ├── highest_price.py
│ ├── readme.md
│ ├── replace the last element.py
│ └── rock paper scissor.py
├── Week 6
├── Challenge Yourself
│ ├── Balls_for_Challenge.py
│ ├── abbreviation.py
│ ├── encryption.py
│ ├── fun_with_words.py
│ ├── missing_letter.py
│ └── readme.md
└── Skill Builder
│ ├── DrNadal.py
│ ├── add_ing.py
│ ├── bowman.py
│ ├── dollar.py
│ ├── duplicate_String.py
│ ├── generate_OTP.py
│ ├── grammatical.py
│ ├── minimum_dist_w1_w2.py
│ ├── permutation.py
│ ├── readme.md
│ └── substring_not_poor.py
├── Week 7
├── Challenge Yourself
│ ├── Best_Mobile_Plan.py
│ ├── Recreation_Fair.py
│ ├── Simplified_Fraction.py
│ ├── longest_word.py
│ ├── readme.md
│ └── sum_of_series.py
└── Skill Builder
│ ├── Best Programmer Baldwin High School.py
│ ├── Fibonacci_recursive_iterative.py
│ ├── High School TopCoder Green Wood High School is set to premier a programming tournament for high school-aged math and science students across the country.py
│ ├── Winter Challenge Swapna is a regular reader of Youth Digest magazine.py
│ ├── Write a Python function that accepts a string and calculates the number of upper case letters and lower case letters. Input format The first line of the input consists of strings.py
│ ├── Write a Python function to reverse words in a string.py
│ ├── Write a function to check whether a number is perfect or not.py
│ ├── Write a program that accepts a string S, and characters c1, c2.py
│ ├── Write a program to obtain the radius of the circle as a parameter and use three different functions to find the diameter, circumference, and area of the circle.py
│ ├── Write a python function program to calculate power of a number raised to other. E.g.- ab using recursion..py
│ └── readme.md
├── Week 8
├── Challenge Yourself
│ ├── capitalize.py
│ ├── common_unique.py
│ ├── floor_ceiling_truncate.py
│ ├── readme.md
│ ├── reverse2D.py
│ └── square_numpy.py
└── Skill Builder
│ ├── common_unique_items.py
│ ├── extract_email.py
│ ├── extract_odd_number.py
│ ├── extract_the_user_id.py
│ ├── indices_of_sorted_elements.py
│ ├── nXn_matrix.py
│ ├── nth_repetition.py
│ ├── parse_the_given_record.py
│ ├── readme.md
│ ├── reverse_2D_array.py
│ └── trigo_maths.py
└── Week 9
├── Challenge Yourself
├── combine_lines.py
├── count_the_frequency.py
├── file_ascending_order.py
├── number_of_lines.py
├── readme.md
└── sum_of_integers.py
└── Skill Builder
├── Maximum_and_Minimum.py
├── accept_file_name.py
├── class_representative.py
├── compare&print_common_content.py
├── count_char_spaces_words.py
├── count_frequency.py
├── flowers.py
├── readme.md
├── representative_selection.py
├── text_in_file.py
└── university_employee.py
/README.md:
--------------------------------------------------------------------------------
1 | # Python Codes
2 | [SRM SEM 3](https://github.com/atharva-narkhede/SRM-Sem3)\
3 | [PYTHON LAB CODES](https://github.com/atharva-narkhede/SRM-Sem3/tree/main/Python/Lab)\
4 | [ISCP HACKERRANK SOLUTIONS](https://github.com/THUNDERANKUSH/HACKERRANK-CODES)
5 |
6 |
7 | Visitor count
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Week 1/Challenge Yourself/1.txt:
--------------------------------------------------------------------------------
1 | a=input()
2 | print('Hello',a,'!','Welcome to Pineaxe Event Management System')
3 |
--------------------------------------------------------------------------------
/Week 1/Challenge Yourself/2.txt:
--------------------------------------------------------------------------------
1 | a=input()
2 | b=int(input())
3 | c=float(input())
4 | print(a)
5 | print('**')
6 | print(b)
7 | print('**')
8 | print(c)
--------------------------------------------------------------------------------
/Week 1/Challenge Yourself/3.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | a=int(input())
3 | b=int(input())
4 | c=(a*b)-1
5 | print(c)
--------------------------------------------------------------------------------
/Week 1/Challenge Yourself/4.txt:
--------------------------------------------------------------------------------
1 | y=int(input())
2 | x=int(input())
3 | c=(y**2)-(x**2)
4 | print(c)
--------------------------------------------------------------------------------
/Week 1/Challenge Yourself/5.txt:
--------------------------------------------------------------------------------
1 | a=float(input())
2 | print('The price is',round(a,2))
--------------------------------------------------------------------------------
/Week 1/Skill Builder/1.txt:
--------------------------------------------------------------------------------
1 | print('If you want to shine like a sun first burn like a sun')
--------------------------------------------------------------------------------
/Week 1/Skill Builder/10.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | word1 = "How"
3 | word2 = "do"
4 | word3 = "you"
5 | word4 = "like"
6 | word5 = "Python"
7 | word6 = "so"
8 | word7 = "far?"
9 | print(word1,word2,word3,word4,word5,word6,word7)
10 |
--------------------------------------------------------------------------------
/Week 1/Skill Builder/11.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | # find speed and round off to two decimal values
3 | distance=245
4 | time=8
5 | speed=distance/time
6 | b=round(speed,2)
7 | print(b)
--------------------------------------------------------------------------------
/Week 1/Skill Builder/12.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | print("Learning Python is fun")
--------------------------------------------------------------------------------
/Week 1/Skill Builder/13.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | a=int(input())
3 | print(a)
--------------------------------------------------------------------------------
/Week 1/Skill Builder/14.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | word1 = " Arise"
3 | word2 = " stop not "
4 | word3 = " goal is "
5 | print(word1,"awake and",word2,"till the", word3,"reached")
6 |
--------------------------------------------------------------------------------
/Week 1/Skill Builder/15.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | a=input()
3 | print(a)
--------------------------------------------------------------------------------
/Week 1/Skill Builder/2.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | a=float(input())
3 | b=float(input())
4 |
5 | product=a*b
6 | print(product)
--------------------------------------------------------------------------------
/Week 1/Skill Builder/3.txt:
--------------------------------------------------------------------------------
1 | numerator = 10
2 | denominator = 10
3 | result = numerator / denominator
4 | print(result)
5 |
--------------------------------------------------------------------------------
/Week 1/Skill Builder/4.txt:
--------------------------------------------------------------------------------
1 | a=float(input())
2 |
3 | b=round(a,2)
4 | print(b)
--------------------------------------------------------------------------------
/Week 1/Skill Builder/5.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | print("2 + 2 =",2 + 2)
--------------------------------------------------------------------------------
/Week 1/Skill Builder/6.txt:
--------------------------------------------------------------------------------
1 | l=int(input())
2 | b=int(input())
3 | perimeter=2*(l+b)
4 | print(perimeter)
--------------------------------------------------------------------------------
/Week 1/Skill Builder/7.txt:
--------------------------------------------------------------------------------
1 | a=float(input())
2 | print(a)
3 |
--------------------------------------------------------------------------------
/Week 1/Skill Builder/8.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | print("Twinkle, twinkle, little star.")
3 | print("How I wonder what you are.")
4 | print("Up above the world so high.")
5 | print("Like a diamond in the sky.")
--------------------------------------------------------------------------------
/Week 1/Skill Builder/9.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | a=int(input())
3 | b=int(input())
4 | c=a-b
5 | print(c)
--------------------------------------------------------------------------------
/Week 1/Skill Builder/temp:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Week 10/Challenge Yourself/class_Book.py:
--------------------------------------------------------------------------------
1 | #Create a Book class that has two attributes :
2 | #title
3 | #author
4 | #two methods:
5 | #1.A method named .get_title() that returns: 'Title: ' + the instance title.
6 | #2.A method named .get_author() that returns: 'Author: ' + the instance author.
7 |
8 |
9 |
10 | class Book:
11 |
12 | def __init__(self, title, author):
13 | self.title = title
14 | self.author = author
15 |
16 | def get_title(self):
17 | return 'Title: ' + self.title
18 |
19 | def get_author(self):
20 | return 'Author: ' + self.author
21 | title=input()
22 | author=input()
23 | book1=Book(title,author)
24 | print(book1.get_title())
25 | print(book1.get_author())
26 |
--------------------------------------------------------------------------------
/Week 10/Challenge Yourself/class_py_solution.py:
--------------------------------------------------------------------------------
1 | #Create a class called py_solution.Write a Python program to get all possible unique subsets from a set of distinct integers.
2 |
3 | class py_solution:
4 | def sub_sets(self, sset):
5 | return self.subsetsRecur([], sorted(sset))
6 |
7 | def subsetsRecur(self, current, sset):
8 | if sset:
9 | return self.subsetsRecur(current, sset[1:]) + self.subsetsRecur(current + [sset[0]], sset[1:])
10 | return [current]
11 | n=list(map(int,input().split()))
12 | print(py_solution().sub_sets(n))
13 |
--------------------------------------------------------------------------------
/Week 10/Challenge Yourself/class_sum.py:
--------------------------------------------------------------------------------
1 | #Create a class called Sum. Write a Python program to find the three elements that sum to zero from a set (array) of n real numbers.
2 |
3 |
4 | class Sum:
5 | def threeSum(self, nums):
6 | nums, result, i = sorted(nums), [], 0
7 | while i < len(nums) - 2:
8 | j, k = i + 1, len(nums) - 1
9 | while j < k:
10 | if nums[i] + nums[j] + nums[k] < 0:
11 | j += 1
12 | elif nums[i] + nums[j] + nums[k] > 0:
13 | k -= 1
14 | else:
15 | result.append([nums[i], nums[j], nums[k]])
16 | j, k = j + 1, k - 1
17 | while j < k and nums[j] == nums[j - 1]:
18 | j += 1
19 | while j < k and nums[k] == nums[k + 1]:
20 | k -= 1
21 | i += 1
22 | while i < len(nums) - 2 and nums[i] == nums[i - 1]:
23 | i += 1
24 | return result
25 | n=list(map(int,input().split()))
26 | print(Sum().threeSum(n))
27 |
--------------------------------------------------------------------------------
/Week 10/Challenge Yourself/readme.md:
--------------------------------------------------------------------------------
1 | # Week 10 Challenge Yourself
2 |
3 | [Create a class called Sum. Write a Python program to find the three elements that sum to zero from a set (array) of n real numbers.](https://github.com/atharva-narkhede/Python/blob/main/Week%2010/Challenge%20Yourself/class_sum.py)
4 |
5 | [Create a class called py_solution.Write a Python program to get all possible unique subsets from a set of distinct integers.](https://github.com/atharva-narkhede/Python/blob/main/Week%2010/Challenge%20Yourself/class_py_solution.py)
6 |
7 | [Create a Book class that has two attributes :title author two methods: 1.A method named .get_title() that returns: 'Title: ' + the instance title. 2.A method named .get_author() that returns: 'Author: ' + the instance author.](https://github.com/atharva-narkhede/Python/blob/main/Week%2010/Challenge%20Yourself/class_Book.py)
8 |
9 |
10 |
11 | Visitor count
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Week 10/Skill Builder/Employee.py:
--------------------------------------------------------------------------------
1 | #Create a class name Employee with the instance attribute firstname and lastname.
2 | #Form the email by joining the first and last name together with a "." in between, and follow it with '@company.com' at the end. Make sure everything is in lowercase.
3 | #Examples:
4 | #emp_1 = Employee("John", "Smith")
5 | #emp_2.email ➞ "mary.sue@company.com"
6 |
7 | class Employee:
8 |
9 | def _init_(self, first_name, last_name):
10 | self.first_name = first_name
11 | self.last_name = last_name
12 | def full_names(self):
13 | return self.first_name + " " + self.last_name
14 |
15 | def email(self):
16 | return self.first_name.lower() + "." + self.last_name.lower() + "@company.com"
17 |
18 | x=input()
19 | y=input()
20 | employee_1 = Employee()
21 | employee_1._init_(x,y)
22 | employee_1.email()
23 | print(employee_1.email())
24 |
--------------------------------------------------------------------------------
/Week 10/Skill Builder/calculator.py:
--------------------------------------------------------------------------------
1 | #Create methods for the Calculator class that can do the following:
2 | #Add two numbers.
3 | #Subtract two numbers.
4 | #Multiply two numbers.
5 | #Divide two numbers.
6 |
7 | class Calculator():
8 | def __init__(self,a,b):
9 | self.a=a
10 | self.b=b
11 | def add(self):
12 | return self.a+self.b
13 | def sub(self):
14 | return self.a-self.b
15 | def mul(self):
16 | return self.a*self.b
17 | def div(self):
18 | return self.a/self.b
19 |
20 |
21 | a = int(input())
22 | b = int(input())
23 |
24 | obj = Calculator(a,b)
25 | choice = int(input())
26 | if choice == 1:
27 | print(obj.add())
28 | elif choice == 2:
29 | print(obj.sub())
30 | elif choice == 3:
31 | print(obj.mul())
32 | elif choice == 4:
33 | print(obj.div())
34 | else:
35 | print("Invalid choice")
36 |
--------------------------------------------------------------------------------
/Week 10/Skill Builder/circle.py:
--------------------------------------------------------------------------------
1 | #Write a program with class named Circle constructed by a radius and two methods which will compute the area and the perimeter of a circle.
2 | #Class Name: Circle
3 | #Method1: area
4 | #Method2: perimeter
5 | #Create an object for the class Circle and display the area and perimeter of a circle.
6 | #Note: Use pi = 3.14
7 |
8 | class Circle():
9 | def __init__(self, r):
10 | self.radius = r
11 |
12 | def area(self):
13 | return self.radius**2*3.14
14 |
15 | def perimeter(self):
16 | return 2*self.radius*3.14
17 |
18 | radius = int(input())
19 | NewCircle = Circle(radius)
20 | print(NewCircle.area())
21 | print(NewCircle.perimeter())
22 |
--------------------------------------------------------------------------------
/Week 10/Skill Builder/class_reverse.py:
--------------------------------------------------------------------------------
1 | #Create a class called Reverse. Write a Python program to reverse a string
2 |
3 | class Reverse:
4 | def string_reverse(str1):
5 | rstr1 = ''
6 | index = len(str1)
7 | while index > 0:
8 | rstr1 += str1[ index - 1 ]
9 | index = index - 1
10 | return rstr1
11 | str1=input()
12 | print(Reverse.string_reverse(str1))
13 |
--------------------------------------------------------------------------------
/Week 10/Skill Builder/country.py:
--------------------------------------------------------------------------------
1 | #Create a class named Country with the following member variables/attributes.
2 | #Get the inputs from the user and display as shown in the sample input and output.
3 |
4 | class country:
5 | def prin(self,x,y,z):
6 | self.x=x
7 | self.y=y
8 | self.z=z
9 | print("Country Name:",self.x)
10 | print("Country Code:",self.y)
11 | print("ISD Code:", self.z)
12 |
13 | x=input()
14 | y=input()
15 | z=input()
16 | r1=country()
17 | r1.prin(x,y,z)
18 |
--------------------------------------------------------------------------------
/Week 10/Skill Builder/pow_class.py:
--------------------------------------------------------------------------------
1 | #Create a class called Pow. Write a Python program to implement pow(x, n).
2 |
3 | class py_solution:
4 | def pow(self, x, n):
5 | if x==0 or x==1 or n==1:
6 | return x
7 |
8 | if x==-1:
9 | if n%2 ==0:
10 | return 1
11 | else:
12 | return -1
13 | if n==0:
14 | return 1
15 | if n<0:
16 | return 1/self.pow(x,-n)
17 | val = self.pow(x,n//2)
18 | if n%2 ==0:
19 | return val*val
20 | return val*val*x
21 | x=int(input())
22 | n=int(input())
23 | print(py_solution().pow(x, n));
24 |
--------------------------------------------------------------------------------
/Week 10/Skill Builder/readme.md:
--------------------------------------------------------------------------------
1 | # Week 10 Skill Builder
2 |
3 | [Create a class called Reverse.Write a Python program to reverse a string](https://github.com/atharva-narkhede/Python/blob/main/Week%2010/Skill%20Builder/class_reverse.py)
4 |
5 | [Write a program to reverse a string word by word. Use Python class to achieve the result.](https://github.com/atharva-narkhede/Python/blob/main/Week%2010/Skill%20Builder/reverse_word_by_word.py)
6 |
7 | [Create a class called Pow. Write a Python program to implement pow(x, n).](https://github.com/atharva-narkhede/Python/blob/main/Week%2010/Skill%20Builder/pow_class.py)
8 |
9 | [Write a Python class named Rectangle constructed by length and breath. Two methods which will compute the area and the perimeter of a Rectangle](https://github.com/atharva-narkhede/Python/blob/main/Week%2010/Skill%20Builder/rectangle.py)
10 |
11 | [Write a program with class named Circle constructed by a radius and two methods which will compute the area and the perimeter of a circle.](https://github.com/atharva-narkhede/Python/blob/main/Week%2010/Skill%20Builder/circle.py)
12 |
13 | [Create methods for the Calculator class that can do the following:](https://github.com/atharva-narkhede/Python/blob/main/Week%2010/Skill%20Builder/calculator.py)
14 |
15 | [Create a class named Country with the following member variables/attributes.](https://github.com/atharva-narkhede/Python/blob/main/Week%2010/Skill%20Builder/country.py)
16 |
17 | [Create a class name Employee with the instance attribute firstname and lastname. Form the email by joining the first and last name together with a "." in between, and follow it with '@company.com' at the end. Make sure everything is in lowercase.](https://github.com/atharva-narkhede/Python/blob/main/Week%2010/Skill%20Builder/Employee.py)
18 |
19 |
20 |
21 |
22 | Visitor count
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Week 10/Skill Builder/rectangle.py:
--------------------------------------------------------------------------------
1 | #Write a Python class named Rectangle constructed by length and breath. Two methods which will compute the area and the perimeter of a Rectangle.
2 | #Class Name: Rectangle
3 | #Method1: area
4 | #Method2: perimeter
5 |
6 |
7 | class Rectangle():
8 | def __init__(self, a,b):
9 | self.a = a
10 | self.b = b
11 |
12 | def area(self):
13 | print(self.a*self.b)
14 |
15 | def perimeter(self):
16 | print(2*(self.a + self.b))
17 |
18 | a=int(input())
19 | b=int(input())
20 |
21 | obj=Rectangle(a,b)
22 | obj.area()
23 | obj.perimeter()
24 |
--------------------------------------------------------------------------------
/Week 10/Skill Builder/reverse_word_by_word.py:
--------------------------------------------------------------------------------
1 | #Write a program to reverse a string word by word. Use Python class to achieve the result.
2 |
3 | class python_string:
4 |
5 | def __init__(self,inp_string):
6 | self.s = inp_string
7 |
8 | def reverse_words(self):
9 |
10 | return ' '.join(reversed(s.split()))
11 |
12 |
13 |
14 | s= input()
15 | #object
16 | reverse = python_string(s)
17 | print(reverse.reverse_words())
18 |
--------------------------------------------------------------------------------
/Week 11/Challenge Yourself/MULTILEVEL_INHERITANCE.py:
--------------------------------------------------------------------------------
1 | #MULTILEVEL INHERITANCE
2 | #Create 3 classes Person, Staff, TemporaryStaff. Here Person class will be inherited by the Staff class and the Staff class will be again inherited by the TemporaryStaff class.
3 |
4 |
5 | class Person:
6 |
7 | def __init__(self,name):
8 |
9 | self.name = name
10 |
11 | def display1(self):
12 |
13 | print('Person Name:{}'.format(self.name))
14 |
15 | class Staff(Person):
16 |
17 | def __init__(self,name,staffid):
18 |
19 | super().__init__(name)
20 | self.staffid=staffid
21 |
22 | def display2(self):
23 |
24 | print('Staff id:{}'.format(self.staffid))
25 |
26 | class Temporarystaff(Staff):
27 |
28 | def __init__(self,name,staffid,days,hours_worked):
29 | super().__init__(name,staffid)
30 |
31 | self.days=days
32 | self.hours_worked=hours_worked
33 |
34 |
35 | def display3(self):
36 |
37 | salary=self.days*self.hours_worked * 50
38 | print("Number of days:{}".format(self.days))
39 | print("Number of hours worked:{}".format(self.hours_worked))
40 | print("Total Salary:{}".format(salary))
41 |
42 |
43 | name=input()
44 | staffid=input()
45 | days=int(input())
46 | hours_worked=int(input())
47 |
48 | obj=Temporarystaff(name, staffid, days,hours_worked)
49 |
50 | obj.display1()
51 | obj.display2()
52 | obj.display3()
--------------------------------------------------------------------------------
/Week 11/Challenge Yourself/Pow.py:
--------------------------------------------------------------------------------
1 | #Write a program to create the following:
2 | #Class Name: Pow parameters: a, b (integers)
3 | #Method: display (to print the value of a to the power of b)
4 | #Class Name: Pow1 (child class of Pow) parameters: inherited from Pow
5 | #Method: display1 (to print the value of a*b)
6 |
7 | class Power:
8 | def __init__(self,a,b):
9 | self.a = a
10 | self.b = b
11 |
12 | def display(self):
13 | print(self.a**self.b)
14 |
15 | class Power1(Power):
16 |
17 | def display1(self):
18 | print(self.a*self.b)
19 |
20 | x = int(input())
21 | y =int(input())
22 | obj=Power1(x,y)
23 | obj.display()
24 | obj.display1()
25 |
--------------------------------------------------------------------------------
/Week 11/Challenge Yourself/banking.py:
--------------------------------------------------------------------------------
1 | #Considering the Banking Scenario, You have different types of accounts like Current Account, Savings Account which inherits the base class Account. Create a base class Account with the fields - name, acc_number, principal_amount, and start_date.
2 | #Create two subclasses CurrentAccount & SavingsAccount for base class 'Account' Declare a method calculateInterest which would return the interest and get end_date as a parameter.
3 | #In SavingsAccount & CurrentAccount - The interest is calculated as simple interest(per year). (Interest 12% for the savings account and 5% for the Current account.)
4 |
5 |
6 |
7 | import datetime
8 |
9 | class Account:
10 |
11 | def __init__(self,name, acc_number, acc_type, principal_amount, start_date):
12 | self.name = name
13 | self.acc_number = acc_number
14 | self.acc_type = acc_type
15 | self.principal_amount = principal_amount
16 | self.start_date = start_date
17 |
18 | def display_details(self):
19 | print(self.name)
20 | print(self.acc_number)
21 | print(self.acc_type)
22 | print(self.principal_amount)
23 |
24 |
25 |
26 | class SavingsAccount(Account):
27 |
28 | def __init__(self,name, acc_number, acc_type, principal_amount, start_date, end_date):
29 | super().__init__(name, acc_number, acc_type, principal_amount, start_date)
30 | self. end_date = end_date
31 |
32 | def calculateInterest(self):
33 |
34 |
35 | s_date_list = self.start_date.split('-')
36 | s_date_y = int(s_date_list[0])
37 | s_date_m = int(s_date_list[1])
38 | s_date_d = int(s_date_list[2])
39 |
40 | e_date_list = self.end_date.split('-')
41 | e_date_y = int(e_date_list[0])
42 | e_date_m = int(e_date_list[1])
43 | e_date_d = int(e_date_list[2])
44 |
45 | d1 = datetime.datetime(e_date_y, e_date_m, e_date_d)
46 | d2 = datetime.datetime(s_date_y, s_date_m, s_date_d)
47 |
48 | month_diff = d1.month - d2.month + 12*(d1.year - d2.year)
49 |
50 | interest = self.principal_amount * (12/100) * (month_diff/12)
51 | print(interest)
52 |
53 | class CurrentAccount(Account):
54 |
55 | def __init__(self,name, acc_number, acc_type, principal_amount, start_date, end_date):
56 | super().__init__(name, acc_number, acc_type, principal_amount, start_date)
57 | self. end_date = end_date
58 |
59 | def calculateInterest(self):
60 |
61 | s_date_list = self.start_date.split('-')
62 | s_date_y = int(s_date_list[0])
63 | s_date_m = int(s_date_list[1])
64 | s_date_d = int(s_date_list[2])
65 |
66 | e_date_list = self.end_date.split('-')
67 | e_date_y = int(e_date_list[0])
68 | e_date_m = int(e_date_list[1])
69 | e_date_d = int(e_date_list[2])
70 |
71 | d1 = datetime.datetime(e_date_y, e_date_m, e_date_d)
72 | d2 = datetime.datetime(s_date_y, s_date_m, s_date_d)
73 |
74 | month_diff = d1.month - d2.month + 12*(d1.year - d2.year)
75 | interest = self.principal_amount * (5/100) * (month_diff/12)
76 | print(interest)
77 |
78 |
79 | acc_name = input()
80 | acc_number = input()
81 | acc_type = input()
82 | principal_amount = float(input())
83 | start_date = input()
84 | end_date = input()
85 |
86 | if acc_type == 'Savings':
87 | obj = SavingsAccount(acc_name, acc_number, acc_type, principal_amount, start_date, end_date)
88 | obj. display_details()
89 | obj. calculateInterest()
90 |
91 | elif acc_type == 'Current':
92 | obj = CurrentAccount(acc_name, acc_number, acc_type, principal_amount, start_date, end_date)
93 | obj. display_details()
94 | obj. calculateInterest()
95 |
96 |
--------------------------------------------------------------------------------
/Week 11/Challenge Yourself/readme.md:
--------------------------------------------------------------------------------
1 | # Week 11 Challenge Yourself
2 |
3 | [MULTILEVEL INHERITANCE](https://github.com/atharva-narkhede/Python/blob/main/Week%2011/Challenge%20Yourself/MULTILEVEL_INHERITANCE.py)
4 |
5 | [Write a program to create the following: Class Name: Pow parameters: a, b (integers) Method: display (to print the value of a to the power of b) Class Name: Pow1 (child class of Pow) parameters: inherited from Pow Method: display1 (to print the value of a*b)](https://github.com/atharva-narkhede/Python/blob/main/Week%2011/Challenge%20Yourself/Pow.py)
6 |
7 | [Considering the Banking Scenario, You have different types of accounts like Current Account, Savings Account which inherits the base class Account. Create a base class Account with the fields - name, acc_number, principal_amount, and start_date. Create two subclasses CurrentAccount & SavingsAccount for base class 'Account' Declare a method calculateInterest which would return the interest and get end_date as a parameter.](https://github.com/atharva-narkhede/Python/blob/main/Week%2011/Challenge%20Yourself/banking.py)
8 |
9 |
10 |
11 |
12 | Visitor count
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Week 11/Skill Builder/Bank_account.py:
--------------------------------------------------------------------------------
1 | #Bank Account
2 | #A class that inherits another class obtains all the latter's attributes and methods are called inheritance.
3 | #The former is called Child class whilst the latter is called Parent class.
4 | #This phenomenon would be very promising in applications dealing with multiple classes that are constituted by similar or more likely the same attributes.
5 | #You will get to know the importance of inheritance from the following problem.
6 | #All types of accounts in a bank have common attributes which can be inherited from an Account class.
7 |
8 | class Account:
9 |
10 | def __init__(self,accName,accNo,bankName):
11 |
12 | self.accName = accName
13 | self.accNo = accNo
14 | self.bankName = bankName
15 |
16 |
17 | def display(self):
18 | print('Account Holder Name:{}'.format(self.accName))
19 | print('Account Number:{}'.format(self.accNo))
20 | print('Bank Name:{}'.format(self.bankName))
21 |
22 |
23 |
24 | class AdditionInfo1(Account):
25 |
26 | def __init__(self,tinNumber):
27 | self.tinNumber = tinNumber
28 | Account.__init__(self,accName_inp,accNo_inp,bankName_inp)
29 |
30 |
31 | def display(self):
32 | print('Account Holder Name:{}'.format(self.accName))
33 | print('Account Number:{}'.format(self.accNo))
34 | print('Bank Name:{}'.format(self.bankName))
35 | print('Tin Number:{}'.format(self.tinNumber))
36 |
37 | class AdditionInfo2(Account):
38 |
39 | def __init__(self,orgName):
40 | self.orgName = orgName
41 | Account.__init__(self,accName_inp,accNo_inp,bankName_inp)
42 |
43 |
44 | def display(self):
45 | print('Account Holder Name:{}'.format(self.accName))
46 | print('Account Number:{}'.format(self.accNo))
47 | print('Bank Name:{}'.format(self.bankName))
48 | print('Organization Name:{}'.format(self.orgName))
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | accName_inp = input()
57 | accNo_inp = input()
58 | bankName_inp = input()
59 | tinNumber = int(input())
60 | orgName = input()
61 |
62 |
63 | select = int(input())
64 |
65 | if select == 1:
66 | accobj = Account(accName_inp,accNo_inp,bankName_inp)
67 | accobj.display()
68 |
69 | if select == 2:
70 | accobj = AdditionInfo1(tinNumber)
71 | accobj.display()
72 |
73 |
74 | if select == 3:
75 | accobj = AdditionInfo2(orgName)
76 | accobj.display()
--------------------------------------------------------------------------------
/Week 11/Skill Builder/Employee.py:
--------------------------------------------------------------------------------
1 | #A company maintains a database that has the details of all the employees.
2 | #There are two levels of employees where Level 1 is the top management having salary more than 10000 and Level 2 is the staffs who are getting a salary less than 10000
3 |
4 |
5 |
6 |
7 | class Employee:
8 | def __init__(self,id,salary):
9 | self.id = id
10 | self.salary = salary
11 |
12 | def display_emp(self):
13 | print(self.id)
14 | print(self.salary)
15 |
16 | class EmpLevel(Employee):
17 | def find_empLevel(self):
18 | if self.salary > 10000:
19 | print('Level 1')
20 | else:
21 | print('Level 2')
22 |
23 |
24 |
25 | inp = input().split()
26 | id = int(inp[0])
27 | salary = float(inp[1])
28 |
29 | obj = EmpLevel(id,salary)
30 | obj.display_emp()
31 | obj.find_empLevel()
--------------------------------------------------------------------------------
/Week 11/Skill Builder/Hierarchical_Inheritance.py:
--------------------------------------------------------------------------------
1 | #Hierarchical Inheritance:
2 | #Create a class 'Parent'. 'Parent' class should have a method 'add' which prints the addition of 2 integers.
3 | #Create a class 'child1' which should be a 'child' class of 'parent' class.it has a method 'sub' which prints subtraction of 2 integers.
4 | #Create a class 'child2' which should be a child class of 'Parent' class. 'Child2' class should have a method 'mul' which prints multiplication of 2 integers.
5 | #Create an object for a 'Child1' class. Call the 2 methods to add and sub from the child1 class object and display the result.
6 | #Create an object for a 'Child2' class. Call the method mul from the child2 class object and display the result.
7 |
8 |
9 | class Parent:
10 |
11 | def __init__(self,a,b):
12 | self.a = a
13 | self.b = b
14 |
15 | def add(self):
16 | print(self.a + self.b)
17 |
18 | class child1(Parent):
19 |
20 | def sub(self):
21 | print(self.a - self.b)
22 |
23 |
24 | class child2(Parent):
25 |
26 | def mul(self):
27 | print(self.a*self.b)
28 |
29 |
30 | a=int(input())
31 | b=int(input())
32 | obj=child1(a,b)
33 | obj.add()
34 | obj.sub()
35 | obj2=child2(a,b)
36 | obj2.mul()
37 |
--------------------------------------------------------------------------------
/Week 11/Skill Builder/Hybrid_Inheritance.py:
--------------------------------------------------------------------------------
1 | #Hybrid Inheritance:
2 | #Create a class 'Parent'. 'Parent' class should have a method 'add' which prints the addition of 2 integers.
3 | #Create a class 'child1' which should be a 'child' class of 'parent' class.it has a method 'sub' which prints subtraction of 2 integers.
4 | #Create a class 'child2' which should be a child class of 'Parent' class. 'Child2' class should have a method 'mul' which prints multiplication of 2 integers.
5 | #Create a class 'child3' which should be a child class of 'child1' class and 'child2' class. 'Child3' class should have a method 'div' which prints the division of 2 integers.
6 |
7 | class Parent:
8 |
9 | def __init__(self,a,b):
10 | self.a = a
11 | self.b = b
12 |
13 | def add(self):
14 | print(self.a + self.b)
15 |
16 | class child1(Parent):
17 |
18 | def sub(self):
19 | print(self.a - self.b)
20 |
21 |
22 | class child2(Parent):
23 |
24 | def mul(self):
25 | print(self.a*self.b)
26 | class child3(child1,child2):
27 |
28 | def div(self):
29 | print(self.a/self.b)
30 |
31 | a=int(input())
32 | b=int(input())
33 | obj=child3(a,b)
34 | obj.add()
35 | obj.sub()
36 | obj.mul()
37 | obj.div()
38 |
--------------------------------------------------------------------------------
/Week 11/Skill Builder/Multilevel_Inheritance.py:
--------------------------------------------------------------------------------
1 | #Multilevel Inheritance:
2 | #Create a class 'Parent'. 'Parent' class should have a method 'add' which prints the addition of 2 integers.
3 | #Create a class 'Child1' which should be a child class of 'Parent' class. 'Child' class should have a method 'sub' which prints subtraction of 2 integers.
4 | #Create a class 'Child2' which should be a child class of 'child1' class. 'Child' class should have a method 'mul' which prints multiplication of 2 integers.
5 |
6 |
7 |
8 | class Parent:
9 |
10 | def __init__(self,a,b):
11 | self.a = a
12 | self.b = b
13 |
14 | def add(self):
15 | print(self.a + self.b)
16 |
17 | class parent2:
18 |
19 | def sub(self):
20 | print(self.a - self.b)
21 |
22 |
23 | class Child(Parent,parent2):
24 |
25 | def mul(self):
26 | print(self.a*self.b)
27 |
28 | a = int(input())
29 | b = int(input())
30 |
31 | ob = Child(a,b)
32 |
33 | ob.add()
34 | ob.sub()
35 | ob.mul()
36 |
--------------------------------------------------------------------------------
/Week 11/Skill Builder/Multiple_inheritance.py:
--------------------------------------------------------------------------------
1 | #Multiple Inheritance
2 | #Create a class 'Parent'. 'Parent' class should have a method 'add' which prints the addition of 2 integers.
3 | #Create a class 'parent2' which is another 'parent' class that should have a method 'sub' which prints subtraction of 2 integers.
4 | #Create a class 'Child' which should be a child class of 'Parent' class and 'parent2' class. 'Child' class should have a method 'mul' which prints multiplication of 2 integers.
5 | #Create an object for a 'Child' class. Call the 3 methods to add, sub and mul from child class object and display the result.
6 |
7 |
8 | class Parent:
9 |
10 | def __init__(self,a,b):
11 | self.a = a
12 | self.b = b
13 |
14 | def add(self):
15 | print(self.a + self.b)
16 |
17 | class parent2:
18 |
19 | def sub(self):
20 | print(self.a - self.b)
21 |
22 |
23 | class Child(Parent,parent2):
24 |
25 | def mul(self):
26 | print(self.a*self.b)
27 |
28 | a = int(input())
29 | b = int(input())
30 |
31 | ob = Child(a,b)
32 |
33 | ob.add()
34 | ob.sub()
35 | ob.mul()
36 |
37 |
--------------------------------------------------------------------------------
/Week 11/Skill Builder/SINGLE_INHERITANCE.py:
--------------------------------------------------------------------------------
1 | #SINGLE INHERITANCE
2 | #Create a class 'Parent'. 'Parent' class should have a method 'add' which prints the addition of 2 integers.
3 | #Create a class 'Child' which should be a child class of 'Parent' class. 'Child' class should have a method 'sub' which prints subtraction of 2 integers.
4 | #Create an object for a 'Child' class. Call the 2 methods add and sub from the child class object and display the result.
5 |
6 |
7 |
8 | class Parent:
9 |
10 | def __init__(self,a,b):
11 | self.a = a
12 | self.b = b
13 |
14 | def add(self):
15 | print(self.a + self.b)
16 |
17 | class Child(Parent):
18 |
19 | def sub(self):
20 | print(self.a - self.b)
21 |
22 |
23 | a = int(input())
24 | b = int(input())
25 |
26 | ob = Child(a,b)
27 |
28 | ob.add()
29 | ob.sub()
30 |
--------------------------------------------------------------------------------
/Week 11/Skill Builder/circle.py:
--------------------------------------------------------------------------------
1 | #Write a class named Circle constructed by a radius and two methods that will compute the area and the perimeter of a circle (Use pi = 3.14).
2 | #Class Name: Circle
3 | #Method1: area
4 | #Method2: perimeter
5 |
6 |
7 |
8 | class Circle():
9 | def __init__(self, r):
10 | self.r = r
11 |
12 | def area(self):
13 | print(self.r**2*3.14)
14 |
15 | def perimeter(self):
16 | print(2*self.r*3.14)
17 |
18 | class Square(Circle):
19 |
20 | def getArea(self):
21 | print(r*r)
22 |
23 | def getPerimeter(self):
24 | print(4*r)
25 |
26 | r=int(input())
27 | obj=Square(r)
28 | obj.area()
29 | obj.perimeter()
30 | obj.getArea()
31 | obj.getPerimeter()
32 |
--------------------------------------------------------------------------------
/Week 11/Skill Builder/readme.md:
--------------------------------------------------------------------------------
1 | # Week 11 Skill Builder
2 |
3 | [Hybrid Inheritance](https://github.com/atharva-narkhede/Python/blob/main/Week%2011/Skill%20Builder/Hybrid_Inheritance.py)
4 |
5 | [Hierarchical Inheritance](https://github.com/atharva-narkhede/Python/blob/main/Week%2011/Skill%20Builder/Hierarchical_Inheritance.py)
6 |
7 | [Bank Account](https://github.com/atharva-narkhede/Python/blob/main/Week%2011/Skill%20Builder/Bank_account.py)
8 |
9 | [Multiple Inheritance](https://github.com/atharva-narkhede/Python/blob/main/Week%2011/Skill%20Builder/Multiple_inheritance.py)
10 |
11 | [A company maintains a database that has the details of all the employees. There are two levels of employees where Level 1 is the top management having salary more than 10000 and Level 2 is the staffs who are getting a salary less than 10000](https://github.com/atharva-narkhede/Python/blob/main/Week%2011/Skill%20Builder/Employee.py)
12 |
13 | [Multilevel Inheritance](https://github.com/atharva-narkhede/Python/blob/main/Week%2011/Skill%20Builder/Multilevel_Inheritance.py)
14 |
15 | [SINGLE INHERITANCE](https://github.com/atharva-narkhede/Python/blob/main/Week%2011/Skill%20Builder/SINGLE_INHERITANCE.py)
16 |
17 | [Write a class named Circle constructed by a radius and two methods that will compute the area and the perimeter of a circle (Use pi = 3.14). Class Name: Circle Method1: area Method2: perimeter](https://github.com/atharva-narkhede/Python/blob/main/Week%2011/Skill%20Builder/circle.py)
18 |
19 |
20 |
21 |
22 | Visitor count
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Week 12/Challenge Yourself/SilverStall.py:
--------------------------------------------------------------------------------
1 | #MULTILEVEL INHERITANCE
2 | #We can implement multi-level inheritance in our application. Let's consider the domain 'Stall' and its types. There exists a multilevel inheritance
3 | #Create a class SilverStall with the following attributes.
4 | #Attributes: name (String), detail (String), owner (Sting), cost (float)
5 | #Total cost computes only the stall cost
6 |
7 |
8 | class SilverStall:
9 | def __init__(self, name, detail, owner, cost):
10 | self.name = name
11 | self.detail = detail
12 | self.owner = owner
13 | self.cost = cost
14 |
15 | def total_cost(self):
16 | cost_value = self.cost
17 | print(cost_value)
18 |
19 | class GoldStall(SilverStall):
20 | def __init__(self, name, detail, owner, cost, tv_set):
21 | super().__init__(name, detail, owner, cost)
22 | self.tv_set = tv_set
23 |
24 | def total_cost(self):
25 | cost_value = self.cost + (100 * self.tv_set)
26 | print(cost_value)
27 |
28 | class PlatinumStall(GoldStall):
29 | def __init__(self, name, detail, owner, cost, tv_set,projector):
30 | super().__init__(name, detail, owner, cost, tv_set)
31 | self.projector = projector
32 |
33 | def total_cost(self):
34 | cost_value = self.cost + (100 * self.tv_set) + (500 * self.projector)
35 | print(cost_value)
36 |
37 |
38 | #Main Program
39 | choice = int(input()) # 1 for silver stall, 2 for gold stall and 3 for platinum stall)
40 | stall_name = input()
41 | stall_detail = input()
42 | stall_owner = input()
43 | stall_cost = float(input())
44 |
45 | if choice == 1: #SilverStall
46 | obj = SilverStall(stall_name,stall_detail, stall_owner,stall_cost)
47 | obj.total_cost()
48 |
49 | elif choice == 2: #GoldStall
50 | tv_set = int(input())
51 | obj = GoldStall(stall_name,stall_detail, stall_owner,stall_cost,tv_set)
52 | obj.total_cost()
53 |
54 | elif choice == 3: #GoldStall
55 | tv_set = int(input())
56 | projector = int(input())
57 | obj = PlatinumStall(stall_name,stall_detail, stall_owner,stall_cost,tv_set,projector)
58 | obj.total_cost()
59 |
60 | else:
61 | print('Invalid Choice')
62 |
--------------------------------------------------------------------------------
/Week 12/Challenge Yourself/bill.py:
--------------------------------------------------------------------------------
1 | #Create a multilevel inheritance based on the image given below. Create suitable attributes and methods as shown in the below table. Get the details from the user and display the data with the total bill amount.
2 | #Create an object only from 'Bill' clause and display all the patient details (check output format) along with the calculated Bill amount.
3 |
4 |
5 | class Patient:
6 | def __init__(self, patient_id, patient_name, age, gender):
7 | self.patient_id = patient_id
8 | self.patient_name = patient_name
9 | self.age = age
10 | self.gender = gender
11 |
12 | def displayData1(self):
13 | print(self.patient_id)
14 | print(self.patient_name)
15 | print(self.age)
16 | print(self.gender)
17 |
18 | class In_Patient(Patient):
19 | def __init__(self, patient_id, patient_name, age, gender,room_number, consultation_fee, test_fee, number_days,rent_per_day):
20 | super(). __init__(patient_id, patient_name, age, gender)
21 | self.room_number = room_number
22 | self.consultation_fee = consultation_fee
23 | self.test_fee = test_fee
24 | self.number_days = number_days
25 | self.rent_per_day = rent_per_day
26 |
27 | def displayData2(self):
28 | print(self.room_number)
29 | print(self.consultation_fee)
30 | print(self.test_fee)
31 | print(self.number_days)
32 | print(self.rent_per_day)
33 |
34 | class Bill(In_Patient):
35 |
36 | def __init__(self, patient_id,patient_name,age, room_number,gender, consultation_fee, test_fee, number_days, rent_per_day):
37 | super().__init__(patient_id,patient_name,age, room_number,gender, consultation_fee, test_fee, number_days, rent_per_day)
38 |
39 |
40 | def total_bill_amount(self):
41 | tot_amt = self.consultation_fee + self.test_fee + (number_days * rent_per_day)
42 | print(tot_amt)
43 |
44 |
45 | #Main Program
46 | patient_id = input()
47 | patient_name = input()
48 | age = input()
49 | gender = input()
50 | room_number = input()
51 | consultation_fee = float(input())
52 | test_fee = float(input())
53 | number_days = int(input())
54 | rent_per_day = float(input())
55 |
56 | obj = Bill(patient_id,patient_name,age,gender, room_number, consultation_fee, test_fee, number_days, rent_per_day)
57 | obj. displayData1()
58 | obj. displayData2()
59 | obj. total_bill_amount()
60 |
--------------------------------------------------------------------------------
/Week 12/Challenge Yourself/class_complex.py:
--------------------------------------------------------------------------------
1 | #Create a class 'Complex' to add two complex numbers. The complex number contains the real parts and the imaginary parts.
2 | #Create two objects c1 and c2. c1 passes the first complex number. c2 passes the second complex number.
3 | #Create a method overloading for the '+' operator, so that it should perform complex numbers addition.
4 | #After creating objects c1 and c2, c1+c2 should display the addition of 2 complex numbers.
5 |
6 |
7 |
8 | class complex_num:
9 | def __init__(self):
10 | self.real = 0
11 | self.imag = 0
12 | def assign(self,rl,img):
13 | self.real = rl
14 | self.imag = img
15 | def __add__(self,obj):
16 | temp = complex_num()
17 | r = self.real + obj.real
18 | i = self.imag + obj.imag
19 | temp.assign(r,i)
20 | return temp
21 | def __mul__(self,obj):
22 | temp = complex_num()
23 | r = self.real*obj.real - self.imag*obj.imag
24 | i = self.real*obj.imag + self.imag*obj.real
25 | temp.assign(r,i)
26 | return temp
27 | def __pow__(self,num):
28 | temp = complex_num()
29 | temp.assign(1,0)
30 | while num>0:
31 | temp *= self
32 | num -= 1
33 | return temp
34 | def __eq__(self,obj):
35 | if self.real == obj.real:
36 | if self.imag == obj.imag:
37 | return True
38 | else:
39 | return False
40 | else:
41 | return False
42 | def __str__(self):
43 | return str(self.real)+'+'+str(self.imag)+'j'
44 | a=int(input())
45 | b=int(input())
46 | c=int(input())
47 | d=int(input())
48 | c1 = complex_num()
49 | c1.assign(a,b)
50 | c2 = complex_num()
51 | c2.assign(c,d)
52 |
53 | print('(',c1+c2,')',sep="")
54 |
--------------------------------------------------------------------------------
/Week 12/Challenge Yourself/readme.md:
--------------------------------------------------------------------------------
1 | # Week 12 Challenge Yourself
2 |
3 | [Create a class 'Complex' to add two complex numbers. The complex number contains the real parts and the imaginary parts. Create two objects c1 and c2. c1 passes the first complex number. c2 passes the second complex number. Create a method overloading for the '+' operator, so that it should perform complex numbers addition. After creating objects c1 and c2, c1+c2 should display the addition of 2 complex numbers.](https://github.com/atharva-narkhede/Python/blob/main/Week%2012/Challenge%20Yourself/class_complex.py)
4 |
5 | [MULTILEVEL INHERITANCE We can implement multi-level inheritance in our application. Let's consider the domain 'Stall' and its types. There exists a multilevel inheritance.Create a class SilverStall with the following attributes.Attributes: name (String), detail (String), owner (Sting), cost (float)Total cost computes only the stall cost](https://github.com/atharva-narkhede/Python/blob/main/Week%2012/Challenge%20Yourself/SilverStall.py)
6 |
7 | [Create a multilevel inheritance based on the image given below. Create suitable attributes and methods as shown in the below table. Get the details from the user and display the data with the total bill amount.Create an object only from 'Bill' clause and display all the patient details (check output format) along with the calculated Bill amount.](https://github.com/atharva-narkhede/Python/blob/main/Week%2012/Challenge%20Yourself/bill.py)
8 |
9 |
10 |
11 |
12 | Visitor count
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Week 12/Skill Builder/Function_Overloading.py:
--------------------------------------------------------------------------------
1 | #Function Overloading
2 | #Create a function 'add'. The function add should perform the following operation.
3 | #The first argument should be the data type of the remaining arguments (str or int) (inp_type)
4 | #It should be able to get any number of arguments (inp1, inp2, inp3,....)
5 | #if the data type is 'str', it should perform string concatenation
6 | #if the data type is 'int', it should perform addition
7 |
8 |
9 | def add(datatype, *args):
10 |
11 | if datatype == 'int':
12 | answer = 0
13 | for x in args:
14 | answer = answer + int(x)
15 | print(answer)
16 |
17 | if datatype == 'str':
18 | answer = ''
19 | for x in args:
20 | answer = answer + x
21 | print(answer)
22 |
23 | inp_type = input()
24 | inp1 = input()
25 | inp2 = input()
26 | inp3 = input()
27 | add(inp_type,inp1,inp2,inp3)
--------------------------------------------------------------------------------
/Week 12/Skill Builder/GST_Calculation.py:
--------------------------------------------------------------------------------
1 | #GST Calculation
2 | #Create a parent class 'Event' with the following attributes.
3 | #Parent class: Event event_type, event_name, event_detail, owner_name, cost_per_day, start_date, end_date (event_type is Exhibition / StageEvent)
4 | #Create child classes Exhibition and StageEvent for the parent class Event.
5 | #Child class: Exhibition Method: to calculate total cost and GST
6 | #Child class: StageEvent Method: to calculate total cost and GST
7 |
8 |
9 | from datetime import date
10 |
11 | class Event:
12 | def __init__(self, event_type, event_name, event_details, owner_name, cost_per_day, start_date, end_date):
13 | self.event_type = event_type
14 | self.event_name = event_name
15 | self.event_details = event_details
16 | self.owner_name = owner_name
17 | self.cost_per_day = cost_per_day
18 | self.start_date = start_date
19 | self.end_date = end_date
20 |
21 |
22 | class Exhibition(Event):
23 |
24 | def calculate_GST(self):
25 |
26 |
27 | s_date_list = self.start_date.split('-')
28 | s_date_y = int(s_date_list[0])
29 | s_date_m = int(s_date_list[1])
30 | s_date_d = int(s_date_list[2])
31 |
32 | e_date_list = self.end_date.split('-')
33 | e_date_y = int(e_date_list[0])
34 | e_date_m = int(e_date_list[1])
35 | e_date_d = int(e_date_list[2])
36 |
37 | d1 = date(e_date_y, e_date_m, e_date_d)
38 | d2 = date(s_date_y, s_date_m, s_date_d)
39 |
40 | date_diff = d1 - d2
41 |
42 |
43 | total_cost = self.cost_per_day * date_diff.days
44 | print(total_cost)
45 | gst_value = 0.05 * total_cost
46 | print(gst_value)
47 |
48 | class StageEvent(Event):
49 |
50 | def calculate_GST(self):
51 |
52 |
53 | s_date_list = self.start_date.split('-')
54 | s_date_y = int(s_date_list[0])
55 | s_date_m = int(s_date_list[1])
56 | s_date_d = int(s_date_list[2])
57 |
58 | e_date_list = self.end_date.split('-')
59 | e_date_y = int(e_date_list[0])
60 | e_date_m = int(e_date_list[1])
61 | e_date_d = int(e_date_list[2])
62 |
63 | d1 = date(e_date_y, e_date_m, e_date_d)
64 | d2 = date(s_date_y, s_date_m, s_date_d)
65 |
66 | date_diff = d1 - d2
67 |
68 |
69 | total_cost = self.cost_per_day * date_diff.days
70 | print(total_cost)
71 | gst_value = 0.15 * total_cost
72 | print(gst_value)
73 |
74 |
75 |
76 | event_type = input()
77 | event_name = input()
78 | event_details = input()
79 | owner_name = input()
80 | cost_per_day = float(input())
81 | start_date = input()
82 | end_date = input()
83 |
84 | if event_type == 'Exhibition':
85 | obj = Exhibition(event_type, event_name, event_details, owner_name, cost_per_day, start_date, end_date)
86 | obj.calculate_GST()
87 |
88 | elif event_type == 'StageEvent':
89 | obj = StageEvent(event_type, event_name, event_details, owner_name, cost_per_day, start_date, end_date)
90 | obj.calculate_GST()
--------------------------------------------------------------------------------
/Week 12/Skill Builder/METHOD_OVERLOADING.py:
--------------------------------------------------------------------------------
1 | #METHOD OVERLOADING
2 | #Create a class named 'Hello'. Define a method 'sayHello'
3 | #Create an object obj.
4 | #Call method 'sayHello' without argument, Output should display 'Hello'.
5 | #Call method 'sayHello' with one argument, Output should display 'Hello 'argument value'' (Ex: If the argument passed is 'John' Output should display 'Hello John'
6 |
7 |
8 | class Hello:
9 |
10 | def sayHello(self, name=None):
11 | if name is not None:
12 | print('Hello ' + name)
13 | else:
14 | print('Hello')
15 |
16 | inp = input()
17 | obj = Hello()
18 | obj.sayHello()
19 | obj.sayHello(inp)
--------------------------------------------------------------------------------
/Week 12/Skill Builder/METHOD_OVERLOADING_compute.py:
--------------------------------------------------------------------------------
1 | #METHOD OVERLOADING
2 | #Create a class named Compute.
3 | #Create a method area. Method area should print the area.
4 | #Create an object obj1
5 |
6 |
7 | class Compute:
8 |
9 | def area(self, x=None, y=None):
10 |
11 | if x!=None and y!=None:
12 | print(x*y)
13 |
14 | elif x!=None:
15 | print(x*x)
16 |
17 | else:
18 | print(0)
19 |
20 |
21 |
22 | input1 = int(input())
23 | input2 = int(input())
24 |
25 |
26 |
27 | obj1 = Compute()
28 |
29 | obj1.area()
30 | obj1.area(input1)
31 | obj1.area(input1,input2)
--------------------------------------------------------------------------------
/Week 12/Skill Builder/Operator_Overloading-Assignment_Operator.py:
--------------------------------------------------------------------------------
1 | # Operator Overloading - Assignment Operator +=
2 | # Create a class named 'Assignment' that should perform += operation of arguments from 2 objects.
3 | # Create a method overloading for += operator, so that it should perform an addition assignment operation.
4 | # Create an object obj1 (passing arguments a and b)
5 | # Create an object obj2 (passing arguments c and d)
6 | # After creating objects obj1 and obj2, print(obj2 += obj1) should display the output as below
7 |
8 | class Assignment:
9 | def __init__(self,a,b):
10 | self.a = a
11 | self.b = b
12 |
13 | def __iadd__(self,other):
14 | self.a += other.a
15 | self.b += other.b
16 | return self.a,self.b
17 |
18 |
19 | a = int(input())
20 | b = int(input())
21 | c = int(input())
22 | d = int(input())
23 |
24 | obj1 = Assignment(a,b)
25 | obj2 = Assignment(c,d)
26 | obj2 += obj1
27 | print(obj2)
28 |
29 |
--------------------------------------------------------------------------------
/Week 12/Skill Builder/Operator_Overloading.py:
--------------------------------------------------------------------------------
1 | # Operator Overloading
2 | # Create a class named 'Power' that should perform the power operation of arguments from 2 objects.
3 | # Create a method overloading for the ** operator, so that it should perform power operation.
4 | # Create an object obj1 and obj2 for class Power (passing arguments a and b respectively)
5 | # After creating objects obj1 and obj2, obj1 ** obj2 should display the output of ab value
6 | # Refer sample input and sample output for formatting specification.
7 |
8 | class Power:
9 | def __init__(self,x):
10 | self.x = x
11 |
12 | def __pow__(self,other):
13 | return self.x ** other.x
14 |
15 |
16 | a = int(input())
17 | b = int(input())
18 | obj1 = Power(a)
19 | obj2 = Power(b)
20 | print(obj1**obj2)
--------------------------------------------------------------------------------
/Week 12/Skill Builder/Operator_Overloading_Mod.py:
--------------------------------------------------------------------------------
1 | #Operator Overloading
2 | #Create a class named 'Mod' that should perform the mod operation of arguments from 2 objects.
3 | #Create a method overloading for % operator, so that it should perform the mod operation.
4 | #Create an object obj1 and obj2 for class Mod (passing arguments a and b respectively)
5 | #After creating objects obj1 and obj2, obj1 % obj2 should display the output.
6 | #Refer sample input and sample output for formatting specification.
7 |
8 |
9 | class Mod:
10 | def __init__(self,x):
11 | self.x = x
12 |
13 | def __mod__(self,other):
14 | return self.x % other.x
15 |
16 |
17 | a = int(input())
18 | b = int(input())
19 | obj1 = Mod(a)
20 | obj2 = Mod(b)
21 | print(obj1 % obj2)
--------------------------------------------------------------------------------
/Week 12/Skill Builder/Printing_object_using_str.py:
--------------------------------------------------------------------------------
1 | #Printing object using str()
2 | #Create a class named 'Vector' to get the values of x and y coordinates.
3 | #Create an object obj1 by passing 2 arguments x and y.
4 | #print(obj1) should display the below output
5 | #xi+yj
6 |
7 | class Vector:
8 | def __init__(self,x,y):
9 | self.x = x
10 | self.y = y
11 |
12 | def __str__(self):
13 | return str(self.x)+'i+'+str(self.y)+'j'
14 |
15 |
16 | x = int(input())
17 | y = int(input())
18 |
19 | obj1 = Vector(x,y)
20 | print(obj1)
21 |
--------------------------------------------------------------------------------
/Week 12/Skill Builder/readme.md:
--------------------------------------------------------------------------------
1 | # Week 12 Skill Builder
2 |
3 | [METHOD OVERLOADING Create a class named 'Hello'. Define a method 'sayHello'](https://github.com/atharva-narkhede/Python/blob/main/Week%2012/Skill%20Builder/METHOD_OVERLOADING.py)
4 |
5 | [Operator Overloading Create a class named 'Power' that should perform the power operation of arguments from 2 objects.Create a method overloading for the ** operator, so that it should perform power operation.Create an object obj1 and obj2 for class Power (passing arguments a and b respectively)After creating objects obj1 and obj2, obj1 ** obj2 should display the output of ab valueRefer sample input and sample output for formatting specification.](https://github.com/atharva-narkhede/Python/blob/main/Week%2012/Skill%20Builder/Operator_Overloading.py)
6 |
7 | [Operator Overloading - Assignment Operator += Create a class named 'Assignment' that should perform += operation of arguments from 2 objects. Create a method overloading for += operator, so that it should perform an addition assignment operation.](https://github.com/atharva-narkhede/Python/blob/main/Week%2012/Skill%20Builder/Operator_Overloading-Assignment_Operator.py)
8 |
9 | [GST Calculation Create a parent class 'Event' with the following attributes.](https://github.com/atharva-narkhede/Python/blob/main/Week%2012/Skill%20Builder/GST_Calculation.py)
10 |
11 | [METHOD OVERLOADING Create a class named Compute. Create a method area. Method area should print the area. Create an object obj1](https://github.com/atharva-narkhede/Python/blob/main/Week%2012/Skill%20Builder/METHOD_OVERLOADING_compute.py)
12 |
13 | [Operator OverloadingCreate a class named 'Mod' that should perform the mod operation of arguments from 2 objects.Create a method overloading for % operator, so that it should perform the mod operation.Create an object obj1 and obj2 for class Mod (passing arguments a and b respectively)](https://github.com/atharva-narkhede/Python/blob/main/Week%2012/Skill%20Builder/Operator_Overloading_Mod.py)
14 |
15 | [Printing object using str() Create a class named 'Vector' to get the values of x and y coordinates. Create an object obj1 by passing 2 arguments x and y. print(obj1) should display the below output xi+yj](https://github.com/atharva-narkhede/Python/blob/main/Week%2012/Skill%20Builder/Printing_object_using_str.py)
16 |
17 | [Function Overloading Create a function 'add'. The function add should perform the following operation.](https://github.com/atharva-narkhede/Python/blob/main/Week%2012/Skill%20Builder/Function_Overloading.py)
18 |
19 |
20 |
21 |
22 | Visitor count
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Week 13/Challenge Yourself/Invalid_Input_format.py:
--------------------------------------------------------------------------------
1 | #Write a function called display() to display the following details.
2 | #name (Datatype should be string)
3 | #deposit amount (Datatype should be float)
4 | #cost per day (Datatype should be float)
5 | #If the above condition does not satisfy, print 'Invalid Input format'. If the condition satisfies, print the above details.
6 |
7 |
8 |
9 | def display(name,depAmt,cost):
10 | print(name)
11 | print(depAmt)
12 | print(cost)
13 |
14 | try:
15 | name = input()
16 | deposit = float(input())
17 | cost = float(input())
18 | display(name,deposit,cost)
19 |
20 | except ValueError as ve:
21 | print('Invalid Input format')
22 |
--------------------------------------------------------------------------------
/Week 13/Challenge Yourself/Seetha.py:
--------------------------------------------------------------------------------
1 | #Seetha wants to understand the process of exception handling.
2 | #She wants to print the variable x which was not assigned any value.
3 | #But she needs to print the error message 'An exception occurred' instead of getting an error 'variable x not declared'.
4 | #Help her in this process.
5 |
6 |
7 | try:
8 | print(x)
9 | except:
10 | print('An exception occurred')
--------------------------------------------------------------------------------
/Week 13/Challenge Yourself/ZeroDivisionError.py:
--------------------------------------------------------------------------------
1 | #You are given 2 values a , b and Number of test cases T.
2 | #Perform Integer division and print the value of a // b.
3 | #In the case of ZeroDivisionError or ValueError, print the error code. Use Exception handling.
4 |
5 |
6 | t = int(input())
7 | for _ in range(t):
8 | a, b = input().split()
9 | try:
10 | div = int(a) // int(b)
11 | print(div)
12 | except ZeroDivisionError as e:
13 | print(e)
14 | except ValueError as e:
15 | print(e)
--------------------------------------------------------------------------------
/Week 13/Challenge Yourself/readme.md:
--------------------------------------------------------------------------------
1 | # Week 13 Challenge Yourself
2 |
3 | [You are given 2 values a , b and Number of test cases T. Perform Integer division and print the value of a // b. In the case of ZeroDivisionError or ValueError, print the error code.](https://github.com/atharva-narkhede/Python/blob/main/Week%2013/Challenge%20Yourself/ZeroDivisionError.py)
4 |
5 | [Write a function called display() to display the following details. name (Datatype should be string) deposit amount (Datatype should be float) cost per day (Datatype should be float)](https://github.com/atharva-narkhede/Python/blob/main/Week%2013/Challenge%20Yourself/Invalid_Input_format.py)
6 |
7 | [Seetha wants to understand the process of exception handling. She wants to print the variable x which was not assigned any value. But she needs to print the error message 'An exception occurred' instead of getting an error 'variable x not declared'.](https://github.com/atharva-narkhede/Python/blob/main/Week%2013/Challenge%20Yourself/Seetha.py)
8 |
9 |
10 |
11 |
12 | Visitor count
13 |
14 |
15 |
--------------------------------------------------------------------------------
/Week 13/Skill Builder/Division_by_Zero.py:
--------------------------------------------------------------------------------
1 | #Write a program to obtain the cost for 'n' days of an item and n as input and calculate the cost per day for the item.
2 | In case, zero is given as input for n, an arithmetic exception is thrown, handle the exception and prompt the user accordingly with an error message 'Division by Zero'
3 |
4 |
5 | c = float(input())
6 | a = int(input())
7 | try:
8 | d = c / a
9 | print(d)
10 | except ZeroDivisionError as e:
11 | print('Division by Zero')
12 |
13 |
--------------------------------------------------------------------------------
/Week 13/Skill Builder/Invalid_Input_format.py:
--------------------------------------------------------------------------------
1 | #Write a function called display() to display the following details.
2 | #name (Datatype should be string)
3 | #deposit amount (Datatype should be float)
4 | #cost per day (Datatype should be float)
5 |
6 |
7 | def display(name,depAmt,cost):
8 | print(name)
9 | print(depAmt)
10 | print(cost)
11 |
12 | try:
13 | name = input()
14 | deposit = float(input())
15 | cost = float(input())
16 | display(name,deposit,cost)
17 |
18 | except ValueError as ve:
19 | print('Invalid Input format')
20 |
--------------------------------------------------------------------------------
/Week 13/Skill Builder/Valid_Integer.py:
--------------------------------------------------------------------------------
1 | #Write a program to get the input as integer from the user. If the input is not a valid integer throw an exception error displaying
2 | #'Invalid Integer'. If the given input is valid integer, display 'Valid Integer'
3 |
4 |
5 | try:
6 | x = int(input())
7 | print('Valid Integer')
8 | except ValueError:
9 | print('Invalid Integer')
10 |
--------------------------------------------------------------------------------
/Week 13/Skill Builder/ZeroDivisionError.py:
--------------------------------------------------------------------------------
1 | #You are given 2 values a , b and Number of test cases T. Perform Integer division and print the value of a // b. In the case of ZeroDivisionError or ValueError, print the error code.
2 |
3 |
4 | t = int(input())
5 | for _ in range(t):
6 | a, b = input().split()
7 | try:
8 | div = int(a) // int(b)
9 | print(div)
10 | except ZeroDivisionError as e:
11 | print(e)
12 | except ValueError as e:
13 | print(e)
14 |
--------------------------------------------------------------------------------
/Week 13/Skill Builder/given_number_is_large_or_small.py:
--------------------------------------------------------------------------------
1 | #Write a program to assume an integer and find whether the given number is large or small than the given input.
2 | #If the number is above or below the user input throw the user-defined exception as “Value is Small” or “Value is large”.
3 | #If it matches with the user assumption display the message as “Well Done”.
4 | #This process should be continued till the user prompts the symbol $.
5 |
6 |
7 |
8 | x = int(input())
9 | ch = 'y'
10 |
11 | while (ch != '$'):
12 | try :
13 | n = int(input())
14 | if nx :
17 | raise Exception('Value is large')
18 | else :
19 | print("Well Done")
20 |
21 | except Exception as e:
22 | print(e)
23 |
24 | ch = input()[0]
25 |
--------------------------------------------------------------------------------
/Week 13/Skill Builder/interactive_calculator.py:
--------------------------------------------------------------------------------
1 | #write an interactive calculator! User input is assumed to be a formula that consists of a number, an operator (at least + and -), and another number, separated by white space (e.g. 1 + 1).
2 | #Split user input using str.split(), and check whether the resulting list is valid:
3 |
4 |
5 | class FormulaError(Exception): pass
6 | def parse_input(user_input):
7 |
8 | input_list = user_input.split()
9 | if len(input_list) != 3:
10 | raise FormulaError('Input does not consist of three elements')
11 | n1, op, n2 = input_list
12 | try:
13 | n1 = float(n1)
14 | n2 = float(n2)
15 | except ValueError:
16 | raise FormulaError('The first and third input value must be numbers')
17 | return n1, op, n2
18 |
19 | def calculate(n1, op, n2):
20 |
21 | if op == '+':
22 | return n1 + n2
23 | if op == '-':
24 | return n1 - n2
25 |
26 | raise FormulaError('{0} is not a valid operator'.format(op))
27 | while True:
28 | user_input = input()
29 | if user_input == 'quit':
30 | print("end of program")
31 | break
32 | n1, op, n2 = parse_input(user_input)
33 | result = calculate(n1, op, n2)
34 | print(result)
35 |
--------------------------------------------------------------------------------
/Week 13/Skill Builder/readme.md:
--------------------------------------------------------------------------------
1 | # Week 13 Skill Builder
2 |
3 | [You are given 2 values a , b and Number of test cases T. Perform Integer division and print the value of a // b. In the case of ZeroDivisionError or ValueError, print the error code.](https://github.com/atharva-narkhede/Python/blob/main/Week%2013/Skill%20Builder/ZeroDivisionError.py)
4 |
5 | [Write a function called display() to display the following details. name (Datatype should be string) deposit amount (Datatype should be float) cost per day (Datatype should be float)](https://github.com/atharva-narkhede/Python/blob/main/Week%2013/Skill%20Builder/Invalid_Input_format.py)
6 |
7 | [Write a python script to find the reciprocal of the given list values and if there is any exception throw that to the user. The given list is a Random list.](https://github.com/atharva-narkhede/Python/blob/main/Week%2013/Skill%20Builder/reciprocal.py)
8 |
9 | [write an interactive calculator! User input is assumed to be a formula that consists of a number, an operator (at least + and -), and another number, separated by white space (e.g. 1 + 1). Split user input using str.split(), and check whether the resulting list is valid:](https://github.com/atharva-narkhede/Python/blob/main/Week%2013/Skill%20Builder/interactive_calculator.py)
10 |
11 | [Given N values, Write a program to find the sum of the N values. If the user input is less than N values, then print Index Error message.](https://github.com/atharva-narkhede/Python/blob/main/Week%2013/Skill%20Builder/sum_of_the_N_values.py)
12 |
13 | [Write a program to assume an integer and find whether the given number is large or small than the given input. If the number is above or below the user input throw the user-defined exception as “Value is Small” or “Value is large”. If it matches with the user assumption display the message as “Well Done”. This process should be continued till the user prompts the symbol $.](https://github.com/atharva-narkhede/Python/blob/main/Week%2013/Skill%20Builder/given_number_is_large_or_small.py)
14 |
15 | [Write a program to get the input as integer from the user. If the input is not a valid integer throw an exception error displaying 'Invalid Integer'. If the given input is valid integer, display 'Valid Integer'](https://github.com/atharva-narkhede/Python/blob/main/Week%2013/Skill%20Builder/Valid_Integer.py)
16 |
17 | [Write a program to obtain the cost for 'n' days of an item and n as input and calculate the cost per day for the item. In case, zero is given as input for n, an arithmetic exception is thrown, handle the exception and prompt the user accordingly with an error message 'Division by Zero'](https://github.com/atharva-narkhede/Python/blob/main/Week%2013/Skill%20Builder/Division_by_Zero.py)
18 |
19 |
20 |
21 |
22 | Visitor count
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Week 13/Skill Builder/reciprocal.py:
--------------------------------------------------------------------------------
1 | #Write a python script to find the reciprocal of the given list values and if there is any exception throw that to the user.
2 | #The given list is a Random list.
3 |
4 |
5 | import sys
6 | n = int(input())
7 | randomList = []
8 | for i in range(0,n):
9 | ele = input()
10 | randomList.append(ele)
11 |
12 |
13 | for entry in randomList:
14 | try:
15 | r = 1/int(entry)
16 | print("The reciprocal of", entry, "is", r)
17 | except:
18 | print("Oops!", sys.exc_info()[0], "occurred.")
19 |
--------------------------------------------------------------------------------
/Week 13/Skill Builder/sum_of_the_N_values.py:
--------------------------------------------------------------------------------
1 | #Given N values, Write a program to find the sum of the N values. If the user input is less than N values, then print Index Error message.Use Exception handling.
2 |
3 |
4 | count = int(input())
5 | inp = input().split()
6 | result = 0
7 | exception = 'False'
8 |
9 | for i in range(count):
10 | try:
11 | result = result + int(inp[i])
12 | except IndexError as e:
13 | print(e)
14 | exception = 'True'
15 | break
16 |
17 | if exception != 'True':
18 | print(result)
19 |
20 |
--------------------------------------------------------------------------------
/Week 14/Challenge Yourself/area_million_sqkm.py:
--------------------------------------------------------------------------------
1 | #Write a program to connect to the database from python and write a query to display the column area_million_sqkm whose country_name is given as input.
2 | #Import pymysql module to connect to the database.
3 |
4 |
5 | import pymysql
6 | def getDbConnection():
7 | connection = pymysql.connect('localhost','rootuser','rootuser','rootuser')
8 | return connection
9 |
10 | def closeDbConnection(connection):
11 | connection.close()
12 |
13 | def getResult(SqlQuery,country):
14 | connection = getDbConnection()
15 | cursor = connection.cursor()
16 | cursor.execute(SqlQuery,(country))
17 | records = cursor.fetchone()
18 | for record in records:
19 | print(record)
20 | closeDbConnection(connection)
21 |
22 |
23 | SqlQuery = "select area_million_sqkm from world where country_name = %s;"
24 |
25 | country = input()
26 |
27 | getResult(SqlQuery,country)
28 |
29 |
--------------------------------------------------------------------------------
/Week 14/Challenge Yourself/display_all_the_employee_names.py:
--------------------------------------------------------------------------------
1 | #Write a program to connect to the database from python and write a query to display all the employee names and their salary(name, salary) whose bonus is less than or equal to the given bonus. Sort the output by ascending order of name.
2 | #Import pymysql module to connect to the database.
3 |
4 |
5 | import pymysql
6 | def getDbConnection():
7 | connection = pymysql.connect('localhost','rootuser','rootuser','rootuser')
8 | return connection
9 |
10 | def closeDbConnection(connection):
11 | connection.close()
12 |
13 | def getResult(SqlQuery,bonus_ref):
14 | connection = getDbConnection()
15 | cursor = connection.cursor()
16 | cursor.execute(SqlQuery,(bonus_ref))
17 | records = cursor.fetchall()
18 | for record in records:
19 | print(record)
20 | closeDbConnection(connection)
21 |
22 |
23 | SqlQuery = "select name,salary from employee e, bonus b where e.empid = b.empid and b.bonus <= %s order by name;"
24 |
25 | bonus_ref = float(input())
26 |
27 | getResult(SqlQuery,bonus_ref)
28 |
29 |
--------------------------------------------------------------------------------
/Week 14/Challenge Yourself/display_the_dependents_details.py:
--------------------------------------------------------------------------------
1 | #Write a program to connect to the database from python and write a query to display the dependents details (first_name, last_name, relationship) for the given employee_id.
2 | #Import pymysql module to connect to the database.
3 |
4 |
5 | import pymysql
6 | def getDbConnection():
7 | connection = pymysql.connect('localhost','rootuser','rootuser','rootuser')
8 | return connection
9 |
10 | def closeDbConnection(connection):
11 | connection.close()
12 |
13 | def getResult(SqlQuery,emp_id):
14 | connection = getDbConnection()
15 | cursor = connection.cursor()
16 | cursor.execute(SqlQuery,(emp_id))
17 | records = cursor.fetchall()
18 | for record in records:
19 | print(record)
20 | closeDbConnection(connection)
21 |
22 |
23 | SqlQuery = "select d.first_name, d.last_name, d. relationship FROM dependents d where employee_id = %s;"
24 |
25 | emp_id = int(input())
26 |
27 |
28 | getResult(SqlQuery,emp_id)
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Week 14/Challenge Yourself/readme.md:
--------------------------------------------------------------------------------
1 | # Week 14 Challenge Yourself
2 |
3 | [Write a program to connect to the database from python and write a query to display all the employee names and their salary(name, salary) whose bonus is less than or equal to the given bonus. Sort the output by ascending order of name.Import pymysql module to connect to the database.](https://github.com/atharva-narkhede/Python/blob/main/Week%2014/Challenge%20Yourself/display_all_the_employee_names.py)
4 |
5 | [Write a program to connect to the database from python and write a query to display the column area_million_sqkm whose country_name is given as input.Import pymysql module to connect to the database.](https://github.com/atharva-narkhede/Python/blob/main/Week%2014/Challenge%20Yourself/area_million_sqkm.py)
6 |
7 | [Write a program to connect to the database from python and write a query to display the dependents details (first_name, last_name, relationship) for the given employee_id.Import pymysql module to connect to the database.](https://github.com/atharva-narkhede/Python/blob/main/Week%2014/Challenge%20Yourself/display_the_dependents_details.py)
8 |
9 |
10 |
11 | Visitor count
12 |
13 |
14 |
--------------------------------------------------------------------------------
/Week 14/Skill Builder/SQL_version.py:
--------------------------------------------------------------------------------
1 | #Write a program to connect to the SQL database from python and print its version.
2 | #The connection details are given below:
3 | #HOST: localhost DB:rootuser
4 | #Default USER: rootuser Default PWD: rootuser
5 |
6 |
7 | import pymysql
8 | def getDbConnection():
9 | connection = pymysql.connect('localhost','rootuser','rootuser','rootuser')
10 | return connection
11 |
12 | def closeDbConnection(connection):
13 | connection.close()
14 |
15 | def readDbVersion():
16 |
17 | connection = getDbConnection()
18 | db_Info = connection.get_server_info()
19 | print(db_Info)
20 | closeDbConnection(connection)
21 |
22 | readDbVersion()
23 |
24 |
--------------------------------------------------------------------------------
/Week 14/Skill Builder/Salesman.py:
--------------------------------------------------------------------------------
1 | #Given a table, Salesman. Connect to database from Python and display names and city of salesman (name, city) for the given city.
2 | #Import pymysql module to connect to database.
3 | #Sort the output by ascending order of names of a salesman.
4 |
5 |
6 | import pymysql
7 | def getDbConnection():
8 | connection = pymysql.connect('localhost', 'rootuser', 'rootuser', 'rootuser')
9 | return connection
10 |
11 | def closeDbConnection(connection):
12 | connection.close()
13 |
14 | def getResult(SqlQuery,cityname):
15 | connection = getDbConnection()
16 | cursor = connection.cursor()
17 | cursor.execute(SqlQuery,(cityname))
18 | records = cursor.fetchall()
19 | for record in records:
20 | print(record)
21 | closeDbConnection(connection)
22 |
23 |
24 | cityname = input()
25 | SqlQuery = "SELECT name,city FROM Salesman WHERE city = %s order by 1;"
26 | getResult(SqlQuery,cityname)
27 |
28 |
--------------------------------------------------------------------------------
/Week 14/Skill Builder/Salesman_commission.py:
--------------------------------------------------------------------------------
1 | #Write a program to connect to database from python and write a query to find those salesmen who get the commission greater than or equal to given range (inclusive of given range). Sort the output by ascending order of salesman_id.
2 | #Import pymysql module to connect to the database.
3 |
4 | import pymysql
5 | def getDbConnection():
6 | connection = pymysql.connect('localhost','rootuser','rootuser','rootuser')
7 | return connection
8 |
9 | def closeDbConnection(connection):
10 | connection.close()
11 |
12 | def getResult(SqlQuery,commission):
13 | connection = getDbConnection()
14 | cursor = connection.cursor()
15 | cursor.execute(SqlQuery,(commission))
16 | records = cursor.fetchall()
17 | for record in records:
18 | print(record)
19 | closeDbConnection(connection)
20 |
21 |
22 | SqlQuery = "select salesman_id, name, city, commission from salesman where commission >= %s order by 1"
23 |
24 | commission = float(input())
25 |
26 | getResult(SqlQuery,commission)
27 |
28 |
--------------------------------------------------------------------------------
/Week 14/Skill Builder/Speciality.py:
--------------------------------------------------------------------------------
1 | #Write a program to connect to database from python and write a query to fetch the number of doctors for a given 'Speciality'
2 | #Import pymysql module to connect to the database.
3 |
4 |
5 | import pymysql
6 | def getDbConnection():
7 | connection = pymysql.connect('localhost','rootuser','rootuser','rootuser')
8 | return connection
9 |
10 | def closeDbConnection(connection):
11 | connection.close()
12 |
13 | def getResult(SqlQuery,Speciality):
14 | connection = getDbConnection()
15 | cursor = connection.cursor()
16 | cursor.execute(SqlQuery,(Speciality))
17 | records = cursor.fetchone()
18 | for record in records:
19 | print(record)
20 | closeDbConnection(connection)
21 |
22 | Speciality = input()
23 |
24 | SqlQuery = "SELECT COUNT(*) FROM Doctor_Info WHERE Speciality = %s;"
25 | getResult(SqlQuery,Speciality)
26 |
27 |
--------------------------------------------------------------------------------
/Week 14/Skill Builder/display_product_name.py:
--------------------------------------------------------------------------------
1 | #Write a program to connect to database from python and write a query to display product_name and quantity_per_unit whose unit_price is greater than the given price. Sort the output by ascending order of product name.
2 | #Import pymysql module to connect to the database.
3 |
4 | import pymysql
5 | def getDbConnection():
6 | connection = pymysql.connect('localhost','rootuser','rootuser','rootuser')
7 | return connection
8 |
9 | def closeDbConnection(connection):
10 | connection.close()
11 |
12 | def getResult(SqlQuery,price):
13 | connection = getDbConnection()
14 | cursor = connection.cursor()
15 | cursor.execute(SqlQuery,(price))
16 | records = cursor.fetchall()
17 | for record in records:
18 | print(record)
19 | closeDbConnection(connection)
20 |
21 |
22 | SqlQuery = "select product_name, quantity_per_unit from products where unit_price > %s order by product_name"
23 |
24 | price = float(input())
25 |
26 | getResult(SqlQuery,price)
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Week 14/Skill Builder/list_of_doctors.py:
--------------------------------------------------------------------------------
1 | #Write a program to connect to database from python and write a query to get the list of doctors(Doctor_Id, Doctor_Name, Hospital_Id) as per the given Speciality and Salary greater than the given salary.
2 | #Sort the output by ascending order of Doctor_Id.
3 | #Import pymysql module to connect to the database.
4 |
5 |
6 | import pymysql
7 | def getDbConnection():
8 | connection = pymysql.connect('localhost','rootuser','rootuser','rootuser')
9 | return connection
10 |
11 | def closeDbConnection(connection):
12 | connection.close()
13 |
14 | def getResult(SqlQuery,Speciality,Salary):
15 | connection = getDbConnection()
16 | cursor = connection.cursor()
17 | cursor.execute(SqlQuery,(Speciality, Salary))
18 | records = cursor.fetchall()
19 | for record in records:
20 | print(record)
21 | closeDbConnection(connection)
22 |
23 |
24 | SqlQuery = "select Doctor_Id, Doctor_Name, Hospital_Id from Doctor_Info where Speciality=%s and Salary > %s order by 1"
25 | Speciality = input()
26 | Salary = float(input())
27 |
28 | getResult(SqlQuery,Speciality,Salary)
29 |
30 |
--------------------------------------------------------------------------------
/Week 14/Skill Builder/number_of_doctors.py:
--------------------------------------------------------------------------------
1 | #Given 2 Tables Hospital and Doctor. Connect to the database from Python and fetch the number of doctors corresponding to each hospital(Hospital_Name, Number of doctors). Sort the output by ascending order of hospital name.
2 | #Import pymysql module to connect to database.
3 |
4 | import pymysql
5 | def getDbConnection():
6 | connection = pymysql.connect('localhost', 'rootuser', 'rootuser', 'rootuser')
7 | return connection
8 |
9 | def closeDbConnection(connection):
10 | connection.close()
11 |
12 | def getResult(SqlQuery):
13 | connection = getDbConnection()
14 | cursor = connection.cursor()
15 | cursor.execute(SqlQuery)
16 | records = cursor.fetchall()
17 | for record in records:
18 | print(record)
19 | closeDbConnection(connection)
20 |
21 |
22 | SqlQuery = "SELECT A.Hospital_Name, count(*) from Hospital A join Doctor B on A.Hospital_Id = B.Hospital_Id group by B.Hospital_Id order by 1;"
23 | getResult(SqlQuery)
24 |
25 |
--------------------------------------------------------------------------------
/Week 14/Skill Builder/readme.md:
--------------------------------------------------------------------------------
1 | # Week 14 Skill Builder
2 |
3 | [Write a program to connect to database from python and write a query to get the list of doctors(Doctor_Id, Doctor_Name, Hospital_Id) as per the given Speciality and Salary greater than the given salary. Sort the output by ascending order of Doctor_Id. Import pymysql module to connect to the database.](https://github.com/atharva-narkhede/Python/blob/main/Week%2014/Skill%20Builder/list_of_doctors.py)
4 |
5 | [Given 2 Tables Hospital and Doctor. Connect to the database from Python and fetch the number of doctors corresponding to each hospital(Hospital_Name, Number of doctors). Sort the output by ascending order of hospital name. Import pymysql module to connect to database.](https://github.com/atharva-narkhede/Python/blob/main/Week%2014/Skill%20Builder/number_of_doctors.py)
6 |
7 | [Write a program to connect to database from python and write a query to display product_name and quantity_per_unit whose unit_price is greater than the given price. Sort the output by ascending order of product name. Import pymysql module to connect to the database.](https://github.com/atharva-narkhede/Python/blob/main/Week%2014/Skill%20Builder/display_product_name.py)
8 |
9 | [Given a table, Salesman. Connect to database from Python and display names and city of salesman (name, city) for the given city. Import pymysql module to connect to database. Sort the output by ascending order of names of a salesman.](https://github.com/atharva-narkhede/Python/blob/main/Week%2014/Skill%20Builder/Salesman.py)
10 |
11 | [Write a program to connect to database from python and write a query to find those salesmen whose first name is equal to the given string. Sort the output by ascending order of last_name. Import pymysql module to connect to the database.](https://github.com/atharva-narkhede/Python/blob/main/Week%2014/Skill%20Builder/salesmen_firstname.py)
12 |
13 | [Write a program to connect to the SQL database from python and print its version. The connection details are given below: HOST: localhost DB:rootuser Default USER: rootuser Default PWD: rootuser](https://github.com/atharva-narkhede/Python/blob/main/Week%2014/Skill%20Builder/SQL_version.py)
14 |
15 | [Write a program to connect to database from python and write a query to fetch the number of doctors for a given 'Speciality' Import pymysql module to connect to the database.](https://github.com/atharva-narkhede/Python/blob/main/Week%2014/Skill%20Builder/Speciality.py)
16 |
17 | [Write a program to connect to database from python and write a query to find those salesmen who get the commission greater than or equal to given range (inclusive of given range). Sort the output by ascending order of salesman_id.](https://github.com/atharva-narkhede/Python/blob/main/Week%2014/Skill%20Builder/Salesman_commission.py)
18 |
19 |
20 |
21 | Visitor count
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Week 14/Skill Builder/salesmen_firstname.py:
--------------------------------------------------------------------------------
1 | #Write a program to connect to database from python and write a query to find those salesmen whose first name is equal to the given string. Sort the output by ascending order of last_name.
2 | #Import pymysql module to connect to the database.
3 |
4 |
5 | import pymysql
6 | def getDbConnection():
7 | connection = pymysql.connect('localhost','rootuser','rootuser','rootuser')
8 | return connection
9 |
10 | def closeDbConnection(connection):
11 | connection.close()
12 |
13 | def getResult(SqlQuery,firstname):
14 | connection = getDbConnection()
15 | cursor = connection.cursor()
16 | cursor.execute(SqlQuery,(firstname))
17 | records = cursor.fetchall()
18 | for record in records:
19 | print(record)
20 | closeDbConnection(connection)
21 |
22 |
23 | SqlQuery = "select salesman_id, first_name,last_name, city, commission from salesman where first_name = %s order by last_name"
24 |
25 | firstname = input()
26 |
27 | getResult(SqlQuery,firstname)
28 |
29 |
--------------------------------------------------------------------------------
/Week 2/Challenge Yourself/Lucky Gifts.txt:
--------------------------------------------------------------------------------
1 | a=int(input())
2 | b=int((a/2)+1)
3 | print(b)
4 |
--------------------------------------------------------------------------------
/Week 2/Challenge Yourself/Pranav and Change.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | x=int(input())
3 | a=int(x/100)
4 | x=x%100
5 | b=int(x/50)
6 | x=x%50
7 | c=int(x/10)
8 | x=x%10
9 | d=int(x/5)
10 | x=x%5
11 | e=int(x/2)
12 | x=x%2
13 | f=int(x)
14 | print(a+b+c+d+e+f)
--------------------------------------------------------------------------------
/Week 2/Challenge Yourself/Talent Show.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | m=int(input())
3 | print(m*3)
4 |
5 |
--------------------------------------------------------------------------------
/Week 2/Challenge Yourself/Total Expenses for the Event.txt:
--------------------------------------------------------------------------------
1 | be=float(input())
2 | te=float(input())
3 | fe=float(input())
4 | le=float(input())
5 | total=be+fe+le+te
6 | a=(be/total)*100
7 | b=(te/total)*100
8 | c=(fe/total)*100
9 | d=(le/total)*100
10 | print("{:.2f}".format(total))
11 | print("{:.2f}".format(a),"%",sep="")
12 | print("{:.2f}".format(b),"%",sep="")
13 | print("{:.2f}".format(c),"%",sep="")
14 | print("{:.2f}".format(d),"%",sep="")
15 |
--------------------------------------------------------------------------------
/Week 2/Challenge Yourself/Trade Fair.txt:
--------------------------------------------------------------------------------
1 | total=int(input())
2 | d1=total/3.5
3 | d2=d1*2
4 | d3=0.5*d1
5 | print("Attendees on day 1 :",int(d1))
6 | print("Attendees on day 2 :",int(d2))
7 | print("Attendees on day 3 :",int(d3))
--------------------------------------------------------------------------------
/Week 2/Challenge Yourself/sample.txt:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Week 2/Skill Builder/Given 2 numbers N,K print the number after performing right shift 'K' times of number N..txt:
--------------------------------------------------------------------------------
1 | n=int(input())
2 | k=int(input())
3 | a=n>>k
4 | print(a)
--------------------------------------------------------------------------------
/Week 2/Skill Builder/bala chocolate.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | a=int(input())
3 | b=int(input())
4 | c=a%b
5 | print(c)
--------------------------------------------------------------------------------
/Week 2/Skill Builder/distance between 2 points.txt:
--------------------------------------------------------------------------------
1 | x1=int(input())
2 | y1=int(input())
3 | x2=int(input())
4 | y2=int(input())
5 | d=(((x2-x1)**2)+((y2-y1)**2))**0.5
6 | print("{:.2f}".format(d))
--------------------------------------------------------------------------------
/Week 2/Skill Builder/event.txt:
--------------------------------------------------------------------------------
1 | a=input()
2 | b=input()
3 | c=int(input())
4 | d=input()
5 | e=float(input())
6 | print("Event Name :",a)
7 | print("Event Type :",b)
8 | print("Expected Count :",c)
9 | print("Paid Entry :",d)
10 | print("Projected Expense : ",round(e,1),"L",sep="")
--------------------------------------------------------------------------------
/Week 2/Skill Builder/exchange 2 niumber.txt:
--------------------------------------------------------------------------------
1 |
2 | a=int(input())
3 | b=int(input())
4 | temp=a;
5 | a=b;
6 | b=temp;
7 | print(a,b)
--------------------------------------------------------------------------------
/Week 2/Skill Builder/kabali ninja.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | a=int(input())
3 | b=int(input())
4 | if(a>b):
5 | print(a-b)
6 | else:
7 | print(b-a)
8 |
--------------------------------------------------------------------------------
/Week 2/Skill Builder/print sep value 3-4.txt:
--------------------------------------------------------------------------------
1 | a=int(input())
2 | b=int(input())
3 | print(a,'-',b,sep='')
4 |
--------------------------------------------------------------------------------
/Week 2/Skill Builder/sample.txt:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Week 2/Skill Builder/shuffle cards.txt:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | a=int(input())
3 | f=1
4 | for i in range(1,a+1):
5 | f*=i
6 | print(f)
--------------------------------------------------------------------------------
/Week 2/Skill Builder/vikram.txt:
--------------------------------------------------------------------------------
1 | a=float(input())
2 | b=float(input())
3 | c=float(input())
4 | gain=((c-a-b)/(a+b))*100
5 |
6 | print("{:.2f}".format(gain))
7 |
--------------------------------------------------------------------------------
/Week 3/Challenge Yourself/Fair_Francis.py:
--------------------------------------------------------------------------------
1 | """
2 | Fair Francis
3 |
4 | "Think Academy" has arranged for a competitive test for engineering students from rural villages. Those successful students of the test will be awarded the scholarship for their GRE/TOEFL preparations at Think Academy. Francis, the co-coordinator and founder of the academy has N different problem sets and there are N students who are appearing for the test. Each problem set contains zero or more problems. He will give each student exactly one problem set. But the problem sets might contain a different number of problems in each one, which looks unfair.
5 |
6 | Since Francis is a fair tutor, he decided to move some problems from the problem set to another problem set (he can do this multiple times), until all problem sets contain the same number of problems.
7 |
8 | Sometimes it's impossible to do so, and he might need to delete some problems completely before moving any problem, then he will start moving the problems. He needs your help to write a program to calculate the minimum number of problems to be deleted, and the minimum number of problems to be moved.
9 | """
10 |
11 | n = int(input())
12 | arr = [int(i) for i in input().split()][:n]
13 | count = 0
14 | avg = sum(arr)//n
15 | for i in range(0,n):
16 | if avg>arr[i]:
17 | count+=avg-arr[i]
18 | rem =sum(arr)-(avg*n)
19 | print(rem,count)
--------------------------------------------------------------------------------
/Week 3/Challenge Yourself/Inverted_Hollow_Pyramid.py:
--------------------------------------------------------------------------------
1 | #Inverted Hollow Pyramid
2 |
3 | #The much-awaited event in the entertainment industry every year is the "Screen Awards". This year the event is going to be organized on December 25 to honor the Artists for their professional excellence in Cinema. The Organizers of the event, J&R Events, decided to design some attractive and LED Matrix panel boards for the show promotions all across the venue.
4 |
5 | #The event organizers wanted to program the display boards with some specific pattern using alphabets and special characters. Help them write a program to design the pattern of an inverted hollow pyramid in the matrix panel, given the number of lines of the pattern.
6 |
7 | n = int(input())
8 | nu = 2*n-1
9 | nn = n
10 | for i in range(1,n+1):
11 | for j in range(1,nu+1):
12 | if(i==1):
13 | print("*",end="")
14 | elif (jnu-i+1):
15 | print("b",end="")
16 | elif (j==i) or (j==nu-i+1):
17 | print("*",end="")
18 | else:
19 | print("i",end="")
20 | print()
--------------------------------------------------------------------------------
/Week 3/Challenge Yourself/Lucky_Cards.py:
--------------------------------------------------------------------------------
1 | """
2 | Lucky Cards
3 |
4 | The Hatfield Game Fair is the premier event of its kind for adults interested in some intellectual and cognitive brain games. Exciting games were organized for kids between the ages group of 8 and 10. One such game was the "Lucky Cards", a simple two-player game, played with a deck of cards. The cards in the deck have these possible names: two, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace. The cards labeled jack, queen, king, ace is collectively known as high cards.
5 |
6 | The numerical equivalent of the high cards is as given below:
7 |
8 | Jack – 11
9 |
10 | Queen – 12
11 |
12 | King – 13
13 |
14 | Ace - 1
15 |
16 | Please note here, though Ace has a numerical equivalent value of 1, it is always considered as the top-rated card. So it is also included in the list of high cards.
17 |
18 | The game organizer selects N cards and places it in the deck face-down on the table. Player A turns over the top card and places it on a pile; then player B turns over the top card and places it on the same pile. A and B alternate turns until the N cards are exhausted. The game is scored as follows:
19 |
20 | if a player turns over an ace that is 1, with at least 4 cards remain to be turned over, and none of the next 4 cards is a high card, that player scores 4 points
21 |
22 | if a player turns over a king that is 13, with at least 3 cards remain to be turned over, and none of the next 3 cards is a high card, that player scores 3 points
23 |
24 | if a player turns over a queen that is 12, with at least 2 cards remain to be turned over, and none of the next 2 cards is a high card, that player scores 2 points
25 |
26 | if a player turns over a jack that is 11, with at least 1 card remains to be turned over, and the next card is not a high card, that player scores 1 point
27 |
28 | Write a program to calculate the scores of the two players.
29 | """
30 |
31 |
32 | n = int(input())
33 | arr = []
34 | for i in range(0,n):
35 | x = int(input())
36 | if x==1:
37 | x=14
38 | arr.append(x)
39 | st=0
40 | a=0
41 | b=0
42 | for i in range(0,n):
43 | if arr[i]>10:
44 | for j in range(1,arr[i]%10+1):
45 | if i+j10):
47 | st=1
48 | break
49 | else:
50 | st=1
51 | break
52 | if(st==0):
53 | if(i%2==0):
54 | a=a+arr[i]%10
55 | print("Player A scores "+str(arr[i]%10)+" point(s)")
56 | else:
57 | b=b+arr[i]%10
58 | print("Player B scores "+str(arr[i]%10)+" point(s)")
59 | st=0
60 | print("Player A: "+str(a)+" point(s)")
61 | print("Player B: "+str(b)+" point(s)")
--------------------------------------------------------------------------------
/Week 3/Challenge Yourself/Math_Challenge.py:
--------------------------------------------------------------------------------
1 | """
2 | Math Challenge
3 |
4 | In connection to the National Mathematics Day celebration, the Regional Mathematical Scholars Society had arranged for a Maths Challenge Event where high school students participated in large numbers. The first level of the challenge was an oral quiz, followed by a written test in the second round.
5 |
6 | In the second round, the problem that the students had to answer goes like this:
7 |
8 | For every positive number ‘n’ we define a function streak(n)=k as the smallest positive integer k such that n+k is not divisible by k+1.
9 | """
10 |
11 |
12 | s = int(input())
13 | n = int(input())
14 | count = 0
15 | num = 1
16 | for i in range(1,n+1):
17 | for j in range(i,n+s):
18 | if (j%num==0):
19 | num+=1
20 | else:
21 | break
22 | if s==num-1:
23 | count+=1
24 | num=1
25 | print(count)
--------------------------------------------------------------------------------
/Week 3/Challenge Yourself/Peter_and_Casino.py:
--------------------------------------------------------------------------------
1 | #Peter and Casino
2 |
3 | #Hotel Royal Gardenia has arranged for an elite business party for the lead industrialists and celebrities of the City. Followed by a dinner buffet, the Event coordinators planned for some casino game events for the high-toned crowd. Peter was a visitor at the party and he takes some number of rubles to the casino with the intention of becoming rich. He plays three machines in turn. Unknown to him, the machines are entirely predictable. Each play costs one ruble. The first machine pays 20 rubles every 25th time it is played; the second machine pays 80 rubles every 120th time it is played; the third pays 8 rubles every 12th time it is played.
4 |
5 | #Given the number of rubles with Peter initially (there will be at least one and fewer than 1000), and the number of times each machine has been played since it last paid, write a program that calculates the number of times Peter plays until he goes broke.
6 |
7 |
8 | n = int(input())
9 | m1=int(input())
10 | m2=int(input())
11 | m3=int(input())
12 | p=0
13 | if m1>=25:
14 | n=n+20*(m1//25)
15 | m1=m1%25
16 | if m2>=120:
17 | n=n+80*(m2//120)
18 | m2=m2%120
19 | if m3>=12:
20 | n=n+8*(m3//12)
21 | m3=m3%12
22 | while(n>0):
23 | m1+=1
24 | n-=1
25 | p+=1
26 | if m1>=25:
27 | n=n+20*(m1//25)
28 | m1=m1%25
29 | if n>0:
30 | m2+=1
31 | n-=1
32 | p+=1
33 | else:
34 | break
35 | if m2>=120:
36 | n=n+80*(m2//120)
37 | m2=m2%120
38 | if n>0:
39 | m3+=1
40 | n-=1
41 | p+=1
42 | else:
43 | break
44 | if m3>=12:
45 | n=n+8*(m3//12)
46 | m3=m3%12
47 | print(""+str(p)+" times")
--------------------------------------------------------------------------------
/Week 3/Challenge Yourself/readme.md:
--------------------------------------------------------------------------------
1 | # WEEK 3 Challenge Yourself
2 |
3 | [Inverted Hollow Pyramid The much-awaited event in the entertainment industry every year is the "Screen Awards". This year the event is going to be organized on December 25 to honor the Artists for their professional excellence in Cinema. The Organizers of the event, J&R Events, decided to design some attractive and LED Matrix panel boards for the show promotions all across the venue. The event organizers wanted to program the display boards with some specific pattern using alphabets and special characters. Help them write a program to design the pattern of an inverted hollow pyramid in the matrix panel, given the number of lines of the pattern.](https://github.com/atharva-narkhede/Python/blob/main/Week%203/Challenge%20Yourself/Inverted_Hollow_Pyramid.py)
4 |
5 | [Peter and Casino Hotel Royal Gardenia has arranged for an elite business party for the lead industrialists and celebrities of the City. Followed by a dinner buffet, the Event coordinators planned for some casino game events for the high-toned crowd. Peter was a visitor at the party and he takes some number of rubles to the casino with the intention of becoming rich. He plays three machines in turn. Unknown to him, the machines are entirely predictable. Each play costs one ruble. The first machine pays 20 rubles every 25th time it is played; the second machine pays 80 rubles every 120th time it is played; the third pays 8 rubles every 12th time it is played. Given the number of rubles with Peter initially (there will be at least one and fewer than 1000), and the number of times each machine has been played since it last paid, write a program that calculates the number of times Peter plays until he goes broke.](https://github.com/atharva-narkhede/Python/blob/main/Week%203/Challenge%20Yourself/Peter_and_Casino.py)
6 |
7 | [Fair Francis "Think Academy" has arranged for a competitive test for engineering students from rural villages. Those successful students of the test will be awarded the scholarship for their GRE/TOEFL preparations at Think Academy. Francis, the co-coordinator and founder of the academy has N different problem sets and there are N students who are appearing for the test. Each problem set contains zero or more problems. He will give each student exactly one problem set. But the problem sets might contain a different number of problems in each one, which looks unfair. Since Francis is a fair tutor, he decided to move some problems from the problem set to another problem set (he can do this multiple times), until all problem sets contain the same number of problems. Sometimes it's impossible to do so, and he might need to delete some problems completely before moving any problem, then he will start moving the problems. He needs your help to write a program to calculate the minimum number of problems to be deleted, and the minimum number of problems to be moved.](https://github.com/atharva-narkhede/Python/blob/main/Week%203/Challenge%20Yourself/Fair_Francis.py)
8 |
9 | [Math Challenge In connection to the National Mathematics Day celebration, the Regional Mathematical Scholars Society had arranged for a Maths Challenge Event where high school students participated in large numbers. The first level of the challenge was an oral quiz, followed by a written test in the second round. In the second round, the problem that the students had to answer goes like this: For every positive number ‘n’ we define a function streak(n)=k as the smallest positive integer k such that n+k is not divisible by k+1. E.g:](https://github.com/atharva-narkhede/Python/blob/main/Week%203/Challenge%20Yourself/Math_Challenge.py)
10 |
11 | [Lucky Cards The Hatfield Game Fair is the premier event of its kind for adults interested in some intellectual and cognitive brain games. Exciting games were organized for kids between the ages group of 8 and 10. One such game was the "Lucky Cards", a simple two-player game, played with a deck of cards. The cards in the deck have these possible names: two, three, four, five, six, seven, eight, nine, ten, jack, queen, king, ace. The cards labeled jack, queen, king, ace is collectively known as high cards. The numerical equivalent of the high cards is as given below: Jack – 11 Queen – 12 King – 13 Ace - 1](https://github.com/atharva-narkhede/Python/blob/main/Week%203/Challenge%20Yourself/Lucky_Cards.py)
12 |
13 |
14 | Visitor count
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Week 3/Skill Builder/Connect_the_ropes.py:
--------------------------------------------------------------------------------
1 | #Connect the Ropes
2 | #It was Christmas Eve and the celebrations remembering the birth of Jesus were going on in full swing at the Cathedral Chapel. The Event Management Team had arranged for some exciting games after the mass worship and feast, where adults and kids of all ages participated very actively. "Connect the Ropes" was organized for the kids where each kid will be given N ropes and the goal of the game is that the kids have to connect all of the ropes with each other to get one rope. When kids connect 2 ropes with each other they lose 'k' units from each rope.
3 |
4 | n,k=map(int,input().split())
5 | L=list(map(int,input().split()))
6 | rope=L[0]+L[1]-(2*k)
7 | for i in range(2,n):
8 | rope+=L[i]-(2*k)
9 | print(rope)
10 |
--------------------------------------------------------------------------------
/Week 3/Skill Builder/GCD.py:
--------------------------------------------------------------------------------
1 | #Given 2 integers N,M find the GCD of N and M.If it cannot be found for given number(s) then print -1
2 |
3 | N=int(input())
4 | M=int(input())
5 | i=1
6 | hcf=0
7 | k=-1
8 | if N==0 and M!=0:
9 | print(M)
10 | elif M==0 and N!=0:
11 | print(N)
12 | else:
13 | while(i<=N and i<=M):
14 | if(N%i==0 and M%i==0):
15 | hcf=i
16 | i+=1
17 | if hcf>0:
18 | print(hcf)
19 | else:
20 | print(k)
21 |
--------------------------------------------------------------------------------
/Week 3/Skill Builder/Hollow_Pyramid.py:
--------------------------------------------------------------------------------
1 | #Hollow Pyramid The much-awaited event in the entertainment industry every year is the "Screen Awards". This year the event is going to be organized on December 25 to honor the Artists for their professional excellence in Cinema. The Organizers of the event, J&R Events, decided to design some attractive and LED Matrix panel boards for the show promotions all across the venue.
2 | # You are using Python
3 | n=int(input())
4 | sp=n
5 | st=-1
6 | for i in range(1,n+1):
7 | sp=sp-1
8 | st=st+2
9 | for j in range(1,sp+1):
10 | print("b",end="")
11 | for k in range(1,st+1):
12 | if(i>1 and i1 and k0:
5 | if n%10==4:
6 | c+=1
7 | n=n//10
8 | print(c)
9 |
10 | #The code below also works the same question
11 | #num = input()
12 | #num = list(num)
13 | #print(num.count("4"))
14 |
--------------------------------------------------------------------------------
/Week 3/Skill Builder/charity_dinner.py:
--------------------------------------------------------------------------------
1 | #Charity Dinner
2 | #WeCanNGO Trust is organizing a charity dinner at St. John’s College. Since older students are both wiser and richer, the members of the trust decide that the price of each ticket will be based on how many years the students have been in the school. A first-year student will buy a PINK ticket, a second-year student will buy a GREEN ticket, a third-year student will buy a RED ticket, and a fourth-year student will buy an ORANGE ticket.Assume that all tickets are sold. Each color of the ticket is uniquely priced. Write a program to output all combinations of tickets that produce exactly the desired amount to be raised. The combinations may appear in a specific order. First ORANGE is considered, then RED, then GREEN, and finally PINK. Also, display the total number of combinations found and the smallest number of tickets to be printed to raise the desired amount so that printing cost is minimized.
3 |
4 | p=int(input())
5 | g=int(input())
6 | r=int(input())
7 | o=int(input())
8 | t=int(input())
9 | count = 0
10 | c = t
11 | for i in range(0,t+1):
12 | for j in range(0,t+1):
13 | for k in range(0,t+1):
14 | for l in range(0,t+1):
15 | if(p*i+g*j+r*k+o*l==t):
16 | print("# of PINK is",i,"# of GREEN is",j,"# of RED is",k,"# of ORANGE is",l)
17 | count+=1
18 | if c>(i+j+k+l):
19 | c=i+j+k+l
20 | print("Total combinations is",count)
21 | print("Minimum number of tickets to print is",c)
22 |
--------------------------------------------------------------------------------
/Week 3/Skill Builder/max_of_3_numbers.py:
--------------------------------------------------------------------------------
1 | #Write a Python function to find the Max of three numbers.
2 | # You are using Python
3 | def max(a,b,c):
4 | if a>b and a>c:
5 | return a
6 | elif b>a and b>c:
7 | return b
8 | else:
9 | return c
10 | a,b,c=input().split(',')
11 | print(max(a,b,c))
12 |
--------------------------------------------------------------------------------
/Week 3/Skill Builder/ram_cfo.py:
--------------------------------------------------------------------------------
1 | #Ram is the CFO of an MNC. He wants to order the employee salaries in ascending order so that he can do a salary hike based on the salary values of employees. He selects you to do the task of sorting the salaries. Sort the salaries in ascending order and pass on the information to Ram.
2 | # You are using Python
3 | a=int(input())
4 | num=list(map(int, input().split()))
5 | num.sort()
6 | print(*num)
7 |
--------------------------------------------------------------------------------
/Week 3/Skill Builder/readme.md:
--------------------------------------------------------------------------------
1 | # WEEK 3 Skill Builder
2 | [Hollow Pyramid The much-awaited event in the entertainment industry every year is the "Screen Awards". This year the event is going to be organized on December 25 to honor the Artists for their professional excellence in Cinema. The Organizers of the event, J&R Events, decided to design some attractive and LED Matrix panel boards for the show promotions all across the venue.](https://github.com/atharva-narkhede/Python/blob/main/Week%203/Skill%20Builder/Hollow_Pyramid.py)
3 |
4 | [Candy Game Mona set off with great zeal to the "Fun Fair 2017". There were numerous activities in the fair, though Mona liked the Candy game. Delicious candies were wrapped in colorful foiled sheets with some random numbers on each of the candies.](https://github.com/atharva-narkhede/Python/blob/main/Week%203/Skill%20Builder/candy%20game.py)
5 |
6 | [Connect the Ropes It was Christmas Eve and the celebrations remembering the birth of Jesus were going on in full swing at the Cathedral Chapel. The Event Management Team had arranged for some exciting games after the mass worship and feast, where adults and kids of all ages participated very actively.](https://github.com/atharva-narkhede/Python/blob/main/Week%203/Skill%20Builder/Connect_the_ropes.py)
7 |
8 | [Ram is the CFO of an MNC. He wants to order the employee salaries in ascending order so that he can do a salary hike based on the salary values of employees. He selects you to do the task of sorting the salaries. Sort the salaries in ascending order and pass on the information to Ram.](https://github.com/atharva-narkhede/Python/blob/main/Week%203/Skill%20Builder/ram_cfo.py)
9 |
10 | [Given 2 integers N,M find the GCD of N and M.If it cannot be found for given number(s) then print -1](https://github.com/atharva-narkhede/Python/blob/main/Week%203/Skill%20Builder/GCD.py)
11 |
12 | [Write a Python function to find the Max of three numbers.](https://github.com/atharva-narkhede/Python/blob/main/Week%203/Skill%20Builder/max_of_3_numbers.py)
13 |
14 | [Series 3 The Event Organizing Company "Buzzcraft" focuses on event management to create a win-win situation for all involved stakeholders. Buzzcraft doesn't look at building one-time associations with clients, instead, aim at creating long-lasting collaborations that will span years to come. This goal of the company has helped them evolve and expand big with organizing many events to date.](https://github.com/atharva-narkhede/Python/blob/main/Week%203/Skill%20Builder/Series_3.py)
15 |
16 | [Kids Love Muffins Louis was celebrating his 10th Birthday and his parents have promised to make the best party ever for him. He will be very happy if he can invite all his friends to this party (he has many friends), but unfortunately, his parents can't invite everyone because they have a limited number of muffins, and they want everyone to be happy. As we all know, kids love to eat a lot of muffins of the same type, let's say a kid will be happy only if he can eat at least K muffins of the same type.](https://github.com/atharva-narkhede/Python/blob/main/Week%203/Skill%20Builder/Kids_love_muffins.py)
17 |
18 | [Charity Dinner WeCanNGO Trust is organizing a charity dinner at St. John’s College. Since older students are both wiser and richer, the members of the trust decide that the price of each ticket will be based on how many years the students have been in the school. A first-year student will buy a PINK ticket, a second-year student will buy a GREEN ticket, a third-year student will buy a RED ticket, and a fourth-year student will buy an ORANGE ticket.](https://github.com/atharva-narkhede/Python/blob/main/Week%203/Skill%20Builder/charity_dinner.py)
19 |
20 | [Series 1 The Event Organizing Company "Buzzcraft" focuses on event management to create a win-win situation for all involved stakeholders. Buzzcraft doesn't look at building one-time associations with clients, instead, aim at creating long-lasting collaborations that will span years to come. This goal of the company has helped them evolve and gain more clients within a notable time.](https://github.com/atharva-narkhede/Python/blob/main/Week%203/Skill%20Builder/Series_1.py)
21 |
22 |
23 | Visitor count
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Week 4/Challenge Yourself/count_number_of_strings.py:
--------------------------------------------------------------------------------
1 | #To count the number of strings where the string length is 2 or more and the first and last characters are the same from a given list of strings. Sample List : ['abc', 'xyz', 'aba', '1221'] Expected Result : 2
2 |
3 | def match_words(words):
4 | ctr = 0
5 |
6 | for word in words:
7 | if len(word) > 2 and word[0] == word[-1]:
8 | ctr += 1
9 | return ctr
10 | n=int(input())
11 | words = input().split()
12 | print(match_words(words))
13 |
--------------------------------------------------------------------------------
/Week 4/Challenge Yourself/readme.md:
--------------------------------------------------------------------------------
1 | # Neocolab Challenge Yourself Codes
2 |
3 | [Write a python program of recursion list sum.](https://github.com/atharva-narkhede/Python/blob/main/Week%204/Challenge%20Yourself/recursion_list_sum.py)
4 |
5 | [Write a Python program to remove and print every third number from a list of numbers until the list becomes empty.](https://github.com/atharva-narkhede/Python/blob/main/Week%204/Challenge%20Yourself/remove%26print_3rd_number_from_list.py)
6 |
7 | [Write a program that accepts n numbers from the user, stores them in a tuple and sorts the tuple, and checks whether an element occurs in the tuple or not.](https://github.com/atharva-narkhede/Python/blob/main/Week%204/Challenge%20Yourself/store_sort_check_tuple.py)
8 |
9 | [Write a Python program to remove an empty tuple(s) from a list of tuples. Given Tuple: L = [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')]
10 | ](https://github.com/atharva-narkhede/Python/blob/main/Week%204/Challenge%20Yourself/remove_element_from_tuple.py)
11 |
12 | [To count the number of strings where the string length is 2 or more and the first and last characters are the same from a given list of strings. Sample List : ['abc', 'xyz', 'aba', '1221'] Expected Result : 2](https://github.com/atharva-narkhede/Python/blob/main/Week%204/Challenge%20Yourself/count_number_of_strings.py)
13 |
14 |
15 | Visitor count
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Week 4/Challenge Yourself/recursion_list_sum.py:
--------------------------------------------------------------------------------
1 | #Write a python program of recursion list sum.
2 |
3 | n= int(input())
4 |
5 | num_list = []
6 | for i in range(n):
7 | x=input()
8 | for i in x.split():
9 | num_list.append(int(i))
10 |
11 |
12 |
13 | sum = 0
14 |
15 | for num in num_list:
16 | sum += num
17 |
18 | print(sum)
--------------------------------------------------------------------------------
/Week 4/Challenge Yourself/remove&print_3rd_number_from_list.py:
--------------------------------------------------------------------------------
1 | #Write a Python program to remove and print every third number from a list of numbers until the list becomes empty.
2 |
3 | # You are using Python
4 | n=int(input())
5 | number_list = []
6 | for i in range(n):
7 | number_list.append(int(input()))
8 | position =3-1
9 | idx = 0
10 | len_list = len(number_list)
11 | while len_list > 0:
12 | idx = (position + idx)% len_list;
13 | print(number_list.pop(idx))
14 | len_list-=1
--------------------------------------------------------------------------------
/Week 4/Challenge Yourself/remove_element_from_tuple.py:
--------------------------------------------------------------------------------
1 | #Write a Python program to remove an empty tuple(s) from a list of tuples. Given Tuple: L = [(), (), ('',), ('a', 'b'), ('a', 'b', 'c'), ('d')]
2 |
3 | # You are using Python
4 | L = [(),(),('',),('a', 'b'), ('a', 'b', 'c'),('d')]
5 | result_list = []
6 | for element in L:
7 | if type(element) == tuple and len(element) == 0:
8 | continue
9 | else:
10 | result_list.append(element)
11 |
12 | L= result_list
13 |
14 | print(L)
--------------------------------------------------------------------------------
/Week 4/Challenge Yourself/store_sort_check_tuple.py:
--------------------------------------------------------------------------------
1 | #Write a program that accepts n numbers from the user, stores them in a tuple and sorts the tuple, and checks whether an element occurs in the tuple or not.
2 |
3 | # You are using Python
4 | n =int(input())
5 |
6 | num_list = []
7 |
8 | for i in range(n):
9 | num_list.append(int(input()))
10 | search_element = int(input())
11 | num_tuple= tuple(num_list)
12 | for num in num_list:
13 | if num== search_element:
14 | print("The element is present in the list")
15 | break
16 | else:
17 | print("The element is not present in the list") #
18 | print("The elements in the tuple are:", num_tuple)
19 | num_list=sorted(num_tuple)
20 | print("The sorted elements of the tuple are:", num_list)
--------------------------------------------------------------------------------
/Week 4/Skill Builder/Given_a_number_N.py:
--------------------------------------------------------------------------------
1 | #Given a number N followed by 2 lists A and B of N integers each. Form a 3rd list C of size N where each element of list C is the sum of the respective elements in lists A and B.
2 |
3 | #Note: Use zip() and sum() function
4 |
5 | N = int(input())
6 | list1 = input().split()
7 | list2 = input().split()
8 |
9 |
10 | for i in range(0,len(list1)):
11 | list1[i] = int(list1[i])
12 | list2[i] = int(list2[i])
13 |
14 | # using zip() + sum() to add two list
15 | res_list = [sum(i) for i in zip(list1, list2)]
16 |
17 | # printing resultant list
18 | print (*res_list)
19 |
--------------------------------------------------------------------------------
/Week 4/Skill Builder/find_kth_smallest_element.py:
--------------------------------------------------------------------------------
1 | #Write a program to find the Kth smallest element in an unsorted list.
2 |
3 | l1 = []
4 | n = int(input())
5 | k = int(input())
6 | for i in range(0,n):
7 | element = int(input())
8 | l1.append(element)
9 | l1.sort()
10 | print(l1[k-1])
--------------------------------------------------------------------------------
/Week 4/Skill Builder/intersection_of_2_lists.py:
--------------------------------------------------------------------------------
1 | #Write a program to find the intersection of two lists.
2 |
3 | num=int(input())
4 | arr=[]
5 | for i in range(0,num):
6 | n=int(input())
7 | arr.append(n)
8 | arr1=[]
9 | for i in range(0,num):
10 | n=input()
11 | arr1.append(int(n))
12 | a=list()
13 | for i in arr:
14 | if i in arr1:
15 | if i not in a:
16 | a.append(int(i))
17 | #a=list(dict.fromkeys(a))
18 | print(a)
--------------------------------------------------------------------------------
/Week 4/Skill Builder/print_max_min_length_of_tuple.py:
--------------------------------------------------------------------------------
1 | #Write a program that accepts n numbers from the user, stores them in a tuple, and prints the length, maximum and minimum number from the tuple.
2 |
3 | numbers=tuple()
4 | newtup=()
5 | i=1
6 | while(i):
7 | num=int(input())
8 | numbers=numbers+(num,)
9 | i=int(input())
10 |
11 | print("The elements in the tuple are:",numbers)
12 | print("The length of the tuple :",len(numbers))
13 | print("The Maximum number is :",max(numbers))
14 | print("The Minimum number is :",min(numbers))
--------------------------------------------------------------------------------
/Week 4/Skill Builder/print_next_smallest_element_in_tuple.py:
--------------------------------------------------------------------------------
1 | #You are given a list. For each element present in the list your task is to print the next smallest number than that number. If it is not the smallest print -1.
2 |
3 | n=int(input())
4 | arr= [int(i) for i in input().split()][:n]
5 | for i in range(0,n):
6 | for j in range(i+1,n):
7 | if arr[i]>arr[j]:
8 | arr[i]=arr[j]
9 | break
10 | if j==n-1:
11 | arr[i]=-1
12 | arr[n-1]=-1
13 | print(*arr)
--------------------------------------------------------------------------------
/Week 4/Skill Builder/print_the_tuple.py:
--------------------------------------------------------------------------------
1 | #Write a program to create a list of tuples with the first element as the number and the second element as the square of the number.
2 |
3 | l_range=int(input())
4 | u_range=int(input())
5 | a=[(x,x**2) for x in range(l_range,u_range+1)]
6 | print(a)
--------------------------------------------------------------------------------
/Week 4/Skill Builder/readme.md:
--------------------------------------------------------------------------------
1 | # Neocolab Week 4 Skill Builder
2 |
3 | [Write a program that accepts n numbers from the user, stores them in a tuple, and prints the length, maximum and minimum number from the tuple.](https://github.com/atharva-narkhede/Python/blob/main/Week%204/Skill%20Builder/print_max_min_length_of_tuple.py)
4 |
5 | [Given a number N followed by 2 lists A and B of N integers each. Form a 3rd list C of size N where each element of list C is the sum of the respective elements in lists A and B.](https://github.com/atharva-narkhede/Python/blob/main/Week%204/Skill%20Builder/Given_a_number_N.py)
6 |
7 | [Write a program that accepts n numbers from the user, stores them in a tuple, searches for an element in the tuple, and sorts the tuple.](https://github.com/atharva-narkhede/Python/blob/main/Week%204/Skill%20Builder/store_search_sort_tuple.py)
8 |
9 | [Write a program that has a list of numbers both positive as well as negatives. Create a new tuple that stores only the positive values from the list](https://github.com/atharva-narkhede/Python/blob/main/Week%204/Skill%20Builder/store_positive_values_from_list.py)
10 |
11 | [You are given a list. For each element present in the list your task is to print the next smallest number than that number. If it is not the smallest print -1.](https://github.com/atharva-narkhede/Python/blob/main/Week%204/Skill%20Builder/print_next_smallest_element_in_tuple.py)
12 |
13 | [Write a program to find the intersection of two lists.](https://github.com/atharva-narkhede/Python/blob/main/Week%204/Skill%20Builder/intersection_of_2_lists.py)
14 |
15 | [Write a program to create a list of tuples with the first element as the number and the second element as the square of the number.](https://github.com/atharva-narkhede/Python/blob/main/Week%204/Skill%20Builder/print_the_tuple.py)
16 |
17 | [Write a program to sort a tuple of tuples by 2nd item](https://github.com/atharva-narkhede/Python/blob/main/Week%204/Skill%20Builder/sort_tuple_of_tuples_by_2nd_item.py)
18 |
19 | [Write a program to remove duplicate numbers from a list.](https://github.com/atharva-narkhede/Python/blob/main/Week%204/Skill%20Builder/remove_duplicate_from_a_list.py)
20 |
21 | [Write a program to find the Kth smallest element in an unsorted list.](https://github.com/atharva-narkhede/Python/blob/main/Week%204/Skill%20Builder/find_kth_smallest_element.py)
22 |
23 |
24 | Visitor count
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Week 4/Skill Builder/remove_duplicate_from_a_list.py:
--------------------------------------------------------------------------------
1 | #Write a program to remove duplicate numbers from a list.
2 |
3 | n= int(input())
4 | l1 = []
5 | for i in range (0,n):
6 | ele = int(input())
7 | l1.append(ele)
8 | l2 = []
9 | for num in l1:
10 | if num not in l2:
11 | l2.append(num);
12 | print(l2)
--------------------------------------------------------------------------------
/Week 4/Skill Builder/sort_tuple_of_tuples_by_2nd_item.py:
--------------------------------------------------------------------------------
1 | #Write a program to sort a tuple of tuples by 2nd item
2 |
3 | def Sort_Tuple(tup):
4 |
5 |
6 | lst = len(tup)
7 | for i in range(0, lst):
8 |
9 | for j in range(0, lst-i-1):
10 | if (tup[j][1] > tup[j + 1][1]):
11 | temp = tup[j]
12 | tup[j]= tup[j + 1]
13 | tup[j + 1]= temp
14 | return tup
15 |
16 |
17 | tup =[('for', 24), ('is', 10), ('Coimbatore', 28),('Collections', 5), ('Towncity', 20), ('a', 15)]
18 |
19 | print(Sort_Tuple(tup))
--------------------------------------------------------------------------------
/Week 4/Skill Builder/store_positive_values_from_list.py:
--------------------------------------------------------------------------------
1 | #Write a program that has a list of numbers both positive as well as negatives. Create a new tuple that stores only the positive values from the list
2 |
3 | numbers=tuple()
4 | newtup=()
5 | n=int(input())
6 | for i in range(0,n):
7 | num=int(input())
8 | numbers=numbers+(num,)
9 | print("The elements in the tuple are:",numbers)
10 | for i in numbers:
11 | if i>0:
12 | newtup+=(i,)
13 | print(newtup)
14 |
--------------------------------------------------------------------------------
/Week 4/Skill Builder/store_search_sort_tuple.py:
--------------------------------------------------------------------------------
1 | #Write a program that accepts n numbers from the user, stores them in a tuple, searches for an element in the tuple, and sorts the tuple.
2 |
3 | numbers=tuple()
4 | newtup=()
5 | n=int(input())
6 | for i in range(0,n):
7 | num=int(input())
8 | numbers=numbers+(num,)
9 | chk=int(input())
10 | if chk in numbers:
11 | print("The element is present in the list")
12 | else:
13 | print("The element is not present in the list")
14 | print("The elements in the tuple are:",numbers)
15 | print("The sorted elements of the tuple are:",sorted(numbers))
16 |
--------------------------------------------------------------------------------
/Week 5/Challenge Yourself/append_list.py:
--------------------------------------------------------------------------------
1 | #Write a program to append one list to another list.
2 |
3 | a=int(input())
4 | x=[]
5 | for i in range(1):
6 | c=str(input()).split()
7 | for j in c:
8 | x.append(int(j))
9 | b=int(input())
10 | y=[]
11 | for i in range(1):
12 | c=str(input()).split()
13 | for j in c:
14 | x.append(int(j))
15 | print(x)
16 |
--------------------------------------------------------------------------------
/Week 5/Challenge Yourself/match_key_values.py:
--------------------------------------------------------------------------------
1 | #Write a Python program to match key values in two dictionaries.
2 |
3 | #Input : {'key1': 1, 'key2': 3, 'key3': 2}, {'key1': 1, 'key2': 2}
4 |
5 | x = {'key1': 1, 'key2': 3, 'key3': 2}
6 | y = {'key1': 1, 'key2': 2}
7 | for (key, value) in set(x.items()) & set(y.items()):
8 | print('%s: %s is present in both x and y'%(key,value))
--------------------------------------------------------------------------------
/Week 5/Challenge Yourself/pizza_delivery_drones.py:
--------------------------------------------------------------------------------
1 | #The Company is launching a network of autonomous pizza delivery drones and wants you to create a flexible rewards system - Pizza Points.
2 | #The rules are simple: if a customer has made at least N orders(min_order) of at least Y(min_price) price, they get a FREE pizza!!!
3 |
4 | # You are using Python
5 | n=int(input())
6 | d={}
7 | for i in range(n):
8 | c=[i for i in input().split()]
9 | s=c[0]
10 | d[s]=[]
11 | for j in range(1,len(c)):
12 | d[s].append(int(c[j]))
13 | minorder=int(input())
14 | maxorder=int(input())
15 | l=[]
16 | for i in d:
17 | count=0
18 | for j in d[i]:
19 | if j>=maxorder:
20 | count+=1
21 | if count>=minorder:
22 | l.append(i)
23 | l.sort()
24 | for i in l:
25 | print(i,end=" ")
26 |
--------------------------------------------------------------------------------
/Week 5/Challenge Yourself/ram_shopping_total.py:
--------------------------------------------------------------------------------
1 | #Ram did grocery shopping. He has a list of items along with the quantity he bought and price of each item.
2 | #Can you please help him to find the total amount he spent.
3 |
4 | # You are using Python
5 | a=int(input())
6 | d={}
7 | e={}
8 | s=0
9 | for i in range(a):
10 | c=input().split()
11 | d[c[0]]=float(c[1])
12 | e[c[0]]=float(c[2])
13 | for j in dict.fromkeys(d):
14 | s+=d[j]*e[j]
15 | print(s)
16 |
--------------------------------------------------------------------------------
/Week 5/Challenge Yourself/readme.md:
--------------------------------------------------------------------------------
1 | # Week 5 Challenge Yourself
2 |
3 |
4 | [Write a Python program to match key values in two dictionaries.Input : {'key1': 1, 'key2': 3, 'key3': 2}, {'key1': 1, 'key2': 2} ](https://github.com/atharva-narkhede/Python/blob/main/Week%205/Challenge%20Yourself/match_key_values.py)
5 |
6 | [X={”p‟,‟r‟,‟o‟,‟g‟,‟r‟,‟a‟,‟m‟,‟m‟,‟i‟,‟n‟,‟g‟, „i‟,‟n‟,‟ p‟,‟y‟,‟t‟,‟h‟,‟o‟,‟n‟} and Y={a,e,i,o,u} Using python sets X and Y, write scripts to find elements](https://github.com/atharva-narkhede/Python/blob/main/Week%205/Challenge%20Yourself/sets_X_and_Y.py)
7 |
8 | [Write a program to append one list to another list](https://github.com/atharva-narkhede/Python/blob/main/Week%205/Challenge%20Yourself/append_list.py)
9 |
10 | [The Company is launching a network of autonomous pizza delivery drones and wants you to create a flexible rewards system - Pizza Points. The rules are simple: if a customer has made at least N orders(min_order) of at least Y(min_price) price, they get a FREE pizza!!!](https://github.com/atharva-narkhede/Python/blob/main/Week%205/Challenge%20Yourself/pizza_delivery_drones.py)
11 |
12 | [Ram did grocery shopping. He has a list of items along with the quantity he bought and price of each item. Can you please help him to find the total amount he spent.](https://github.com/atharva-narkhede/Python/blob/main/Week%205/Challenge%20Yourself/ram_shopping_total.py)
13 |
14 |
15 |
16 |
17 | Visitor count
18 |
19 |
20 |
--------------------------------------------------------------------------------
/Week 5/Challenge Yourself/sets_X_and_Y.py:
--------------------------------------------------------------------------------
1 | #X={”p‟,‟r‟,‟o‟,‟g‟,‟r‟,‟a‟,‟m‟,‟m‟,‟i‟,‟n‟,‟g‟, „i‟,‟n‟,‟ p‟,‟y‟,‟t‟,‟h‟,‟o‟,‟n‟} and Y={a,e,i,o,u} Using python sets X and Y, write scripts to find elements
2 | #a) that occur only in X but not in Y
3 | #b) that occur in X or Y.
4 | #c) that occur in X and Y.
5 | #d) Create a new set by deleting all vowels from X.
6 | #e) Check whether X contains all elements of Y, if so print “All vowels are in X”.
7 |
8 | # You are using Python
9 | X={"p","r","o","g","r","a","m","m","i","n","g","i","n","p","y","t","h","o","n"}
10 | Y={"a","e","i","o","u"}
11 |
12 | A=X.difference(Y)
13 | a=list(A)
14 | a.sort()
15 |
16 | B=set()
17 | B.update(X)
18 | B.update(Y)
19 | b=list(B)
20 | b.sort()
21 |
22 | C=set()
23 | for i in X:
24 | for j in Y:
25 | if i==j:
26 | C.add(i)
27 | c=list(C)
28 | c.sort()
29 |
30 | D=set()
31 | D=X.difference(Y)
32 | d=list(D)
33 | d.sort()
34 |
35 | print(a)
36 | print(b)
37 | print(c)
38 | print(d)
39 | if Y.issubset(X):
40 | print("All vowels are in X")
41 |
--------------------------------------------------------------------------------
/Week 5/Skill builder/Generate_set.py:
--------------------------------------------------------------------------------
1 | #Write a Python program to generate a set in a set of lists whose sum of elements is the highest
2 |
3 | list1 = []
4 | list2 = []
5 | list3 = []
6 | list4 = []
7 | list1 = input().split()
8 | list2 = input().split()
9 | list3 = input().split()
10 | list4 = input().split()
11 | for i in range (0,len(list1)):
12 | list1[i] = int(list1[i])
13 | for i in range (0,len(list2)):
14 | list2[i] = int(list2[i])
15 | for i in range (0,len(list3)):
16 | list3[i] = int(list3[i])
17 | for i in range (0,len(list4)):
18 | list4[i] = int(list4[i])
19 | set1 = set(list1)
20 | set2 = set(list2)
21 | set3 = set(list3)
22 | set4 = set(list4)
23 | sum1 = 0
24 | sum2 = 0
25 | sum3 = 0
26 | sum4 = 0
27 | for num in list1:
28 | sum1 = sum1+num
29 | for num in list2:
30 | sum2 = sum2+num
31 | for num in list3:
32 | sum3 = sum3+num
33 | for num in list4:
34 | sum4 = sum4+num
35 | maximum = max(sum1,sum2,sum3,sum4)
36 | print(maximum)
37 | if sum1 == maximum:
38 | print(sorted(set1))
39 | if sum2 == maximum:
40 | print(sorted(set2))
41 | if sum3 == maximum:
42 | print(sorted(set3))
43 | if sum4 == maximum:
44 | print(sorted(set4))
45 |
--------------------------------------------------------------------------------
/Week 5/Skill builder/Sanjay_and_Rahul.py:
--------------------------------------------------------------------------------
1 | #Sanjay and Rahul have a set of color crayons. Sanjay has a set of colors whereas Rahul has a set of colors. Write a program to find the colors they have in common. Print the colors that Rahul has but not Sanjay. Sanjay lost his Green color. Update this information.
2 | #Note: Sort the sets before printing
3 |
4 |
5 | # You are using Python
6 | list1 = input().split()
7 | list2 = input().split()
8 | set1 = set(list1)
9 | set2 = set(list2)
10 | print(sorted(set1 & set2))
11 | print(sorted(set2.difference(set1)))
12 | set1.remove('green')
13 | print(sorted(set1))
--------------------------------------------------------------------------------
/Week 5/Skill builder/Stationery_shop.py:
--------------------------------------------------------------------------------
1 | #Create a dictionary for a stationery shop (Pen, Pencil, Paper, etc…) and print all unique values in a dictionary.
2 |
3 | n= int(input())
4 | stat = []
5 | for i in range(n):
6 | dict1 = {}
7 | inp = input().split(':')
8 | dict1[inp[0]] = inp[1]
9 | stat.append(dict1)
10 | u_value = set(val for dict1 in stat for val in dict1.values())
11 | print(sorted((set(u_value))))
12 |
--------------------------------------------------------------------------------
/Week 5/Skill builder/concatenate_three_dictionaries.py:
--------------------------------------------------------------------------------
1 | #Write a program to concatenate three dictionaries to create a new one.
2 |
3 |
4 | # You are using Python
5 | n=int(input())
6 | list1=[]
7 | list2=[]
8 | list3=[]
9 | for i in range(n):
10 | dict1 = {}
11 | inp = input().split(':')
12 | dict1[inp[0]] = inp[1]
13 | list1.append(dict1)
14 | for i in range(n):
15 | dict2 = {}
16 | inp = input().split(':')
17 | dict2[inp[0]] = inp[1]
18 | list2.append(dict2)
19 | for i in range(n):
20 | dict3 = {}
21 | inp = input().split(':')
22 | dict3[inp[0]] = inp[1]
23 | list3.append(dict3)
24 | for d in list2:
25 | list1.append(d)
26 | for d in list3:
27 | list1.append(d)
28 | print(list1)
--------------------------------------------------------------------------------
/Week 5/Skill builder/convert_a_set_of_integers.py:
--------------------------------------------------------------------------------
1 | #Write a Python program to convert a set of integers into a single integer
2 |
3 |
4 | # You are using Python
5 | numbers=list(map(int,input().split()))
6 | for i in numbers:
7 | print(i,end="")
--------------------------------------------------------------------------------
/Week 5/Skill builder/create_a_set_with_the_positive_integers.py:
--------------------------------------------------------------------------------
1 | #Write a Python program to create a set with the positive integers and arrange the numbers in ascending order.
2 |
3 | # You are using Python
4 | input_list = input().split()
5 | for i in range(0,len(input_list)):
6 | input_list[i] = int(input_list[i])
7 | S1 = set(input_list)
8 | x = sorted(S1)
9 | print(x)
--------------------------------------------------------------------------------
/Week 5/Skill builder/get_the_top_three_items.py:
--------------------------------------------------------------------------------
1 |
2 | #Write a program to get the top three items in a shop using dictionaries.
3 |
4 | # You are using Python
5 | from heapq import nlargest
6 | from operator import itemgetter
7 | n = int(input())
8 | items = {}
9 | for i in range(n):
10 | dict1 = {}
11 | inp = input().split(':')
12 | items[inp[0]] = inp[1]
13 | for name, value in nlargest(3, items.items(), key=itemgetter(1)):
14 | print(name, value)
--------------------------------------------------------------------------------
/Week 5/Skill builder/highest_price.py:
--------------------------------------------------------------------------------
1 | from heapq import nlargest
2 | from operator import itemgetter
3 | n=int(input())
4 | items = {}
5 |
6 | for i in range(n):
7 | name, value = input().split()
8 | items[name] = float(value)
9 | for name, value in nlargest(1, items.items(), key=itemgetter(1)):
10 | print(name, float(value))
11 |
--------------------------------------------------------------------------------
/Week 5/Skill builder/readme.md:
--------------------------------------------------------------------------------
1 | # Neocolab Week 5 Skill Builder
2 |
3 | [Q1. Sanjay and Rahul have a set of color crayons. Sanjay has a set of colors whereas Rahul has a set of colors. Write a program to find the colors they have in common. Print the colors that Rahul has but not Sanjay. Sanjay lost his Green color. Update this information.](https://github.com/atharva-narkhede/Python/blob/main/Week%205/Skill%20builder/Sanjay_and_Rahul.py)
4 |
5 | [Q2. Write a program to concatenate three dictionaries to create a new one.](https://github.com/atharva-narkhede/Python/blob/main/Week%205/Skill%20builder/concatenate_three_dictionaries.py)
6 |
7 | [Q3. Write a Python program to convert a set of integers into a single integer](https://github.com/atharva-narkhede/Python/blob/main/Week%205/Skill%20builder/convert_a_set_of_integers.py)
8 |
9 | [Q4. Write a Python program to create a set with the positive integers and arrange the numbers in ascending order.](https://github.com/atharva-narkhede/Python/blob/main/Week%205/Skill%20builder/create_a_set_with_the_positive_integers.py)
10 |
11 | [Q5. Write a program to get the top three items in a shop using dictionaries.](https://github.com/atharva-narkhede/Python/blob/main/Week%205/Skill%20builder/get_the_top_three_items.py)
12 |
13 | [Q6. Write a program to replace the last element in a set with another set. Print the resultant set in sorted order](https://github.com/atharva-narkhede/Python/blob/main/Week%205/Skill%20builder/replace%20the%20last%20element.py)
14 |
15 | [Q7. Let P represent Paper, R represent Rock and S represent Scissors. Given 2 out of the 3 determine which wins. If it's a drawing print D. Use Dictionary concept to get the result.](https://github.com/atharva-narkhede/Python/blob/main/Week%205/Skill%20builder/rock%20paper%20scissor.py)
16 |
17 | [Q8. Write a Python program to generate a set in a set of lists whose sum of elements is the highest.](https://github.com/atharva-narkhede/Python/blob/main/Week%205/Skill%20builder/Generate_set.py)
18 |
19 | [Q9. Write a python program to get a item in a bill which has the highest price. Items and prices are storing in dictionary format.](https://github.com/atharva-narkhede/Python/blob/main/Week%205/Skill%20builder/highest_price.py)
20 |
21 | [Q10. Create a dictionary for a stationery shop (Pen, Pencil, Paper, etc…) and print all unique values in a dictionary.](https://github.com/atharva-narkhede/Python/blob/main/Week%205/Skill%20builder/Stationery_shop.py)
22 |
23 |
24 | Visitor count
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Week 5/Skill builder/replace the last element.py:
--------------------------------------------------------------------------------
1 | #Write a program to replace the last element in a set with another set. Print the resultant set in sorted order
2 |
3 |
4 |
5 |
6 | # You are using Python
7 | input_list1 = input().split()
8 | for i in range(0,len(input_list1)):
9 | input_list1[i] = int(input_list1[i])
10 |
11 |
12 | input_list2 = input().split()
13 | for i in range(0,len(input_list2)):
14 | input_list2[i] = int(input_list2[i])
15 |
16 | S1 = set(input_list1)
17 | S2 = set(input_list2)
18 |
19 | S1 = set(input_list1[:-1])
20 | S1.update(S2)
21 | x = sorted(S1)
22 | print(x)
--------------------------------------------------------------------------------
/Week 5/Skill builder/rock paper scissor.py:
--------------------------------------------------------------------------------
1 | #Let P represent Paper, R represent Rock and S represent Scissors. Given 2 out of the 3 determine which wins. If it's a drawing print D. Use Dictionary concept to get the result.
2 |
3 |
4 |
5 |
6 |
7 | # You are using Python
8 | beats = {'P': 'S',
9 | 'R': 'P',
10 | 'S': 'R'}
11 |
12 | p = input()
13 | p_lst = p.split()
14 |
15 |
16 | if p_lst[0] == beats[p_lst[1]]:
17 | print(p_lst[0])
18 | elif p_lst[1] == beats[p_lst[0]]:
19 | print(p_lst[1])
20 | elif p_lst[0] == p_lst[1]:
21 | print('D')
--------------------------------------------------------------------------------
/Week 6/Challenge Yourself/Balls_for_Challenge.py:
--------------------------------------------------------------------------------
1 | #Balls for Challenge
2 | #The Circoloco Children Carnival is the City’s largest and successful event dedicated to children and families.
3 | #The main focus at the carnival is the workshop arena where kids can participate in engaging and educational activities.
4 |
5 |
6 | s1=input()
7 | s2=input()
8 | for i in range(0,len(s1)):
9 | if(s1[i]==s2[i]):
10 | if(s1[i]=="W"):
11 | print("B",end="")
12 | else:
13 | print("W",end="")
14 | else:
15 | print("B",end="")
16 |
--------------------------------------------------------------------------------
/Week 6/Challenge Yourself/abbreviation.py:
--------------------------------------------------------------------------------
1 | #Write a program to print the abbreviation for a given sentence.
2 | s=input()
3 | s=s.split()
4 | print("The abbreviation is")
5 | for i in range(0,len(s)):
6 | s[i]=list(s[i])
7 |
8 | if ord(s[i][0]) in range(65,91):
9 | print(s[i][0],end="")
10 |
--------------------------------------------------------------------------------
/Week 6/Challenge Yourself/encryption.py:
--------------------------------------------------------------------------------
1 | #The Encryption Algorithm: Encrypt the given input with these steps.
2 | #Eg: apple
3 | #Step 1:
4 | #Reverse the input (elppa)
5 | #Step 2:
6 | #Replace the below letters using the given values (1lpp0)
7 | #Step3:
8 | #Add 'aca' to the end of the word. (1lpp0aca)
9 |
10 |
11 |
12 | def encrypt(word):
13 | v= {'a':'0','e':'1','o':'2','u':'3'}
14 | return ''.join(v[i] if i in v else i for i in word[::-1]) +'aca'
15 |
16 |
17 | word = input()
18 | print(encrypt(word))
19 |
--------------------------------------------------------------------------------
/Week 6/Challenge Yourself/fun_with_words.py:
--------------------------------------------------------------------------------
1 | #"Juniors Network" Cartoon Channel is the favorite channel of all the kids in the city.
2 | #As it is vacation time, the channel had introduced several new segments to engage the kids in a more creative manner.
3 | #"Fun with Words" is one such activity involving English alphabets, where school kids were invited to participate.
4 |
5 |
6 |
7 | n = [int(i) for i in input().split()][:2]
8 | st = [str(i) for i in input().split()][:n[0]]
9 | arr = [None]*n[1]
10 | for i in range(0,n[1]):
11 | arr[i]=input()
12 | arr[i]=arr[i].split()
13 | nu = int(arr[i].pop(0))
14 | arr[i]=arr[i][:nu]
15 | s=0
16 | for i in st:
17 | for j in range(0,n[1]):
18 | if i in arr[j]:
19 | print("Yes",end=" ")
20 | s=1
21 | break
22 | if s==0:
23 | print("No",end=" ")
24 | s=0
25 |
--------------------------------------------------------------------------------
/Week 6/Challenge Yourself/missing_letter.py:
--------------------------------------------------------------------------------
1 | # Write a program to find the missing letter given a list of increasing letters.
2 | def missing_letter(lst):
3 | for a,b in zip(lst,lst[1:]):
4 | if ord(b) - ord(a) > 1:
5 | return chr(ord(a) + 1)
6 |
7 | inp_list = input().split()
8 | print(missing_letter(inp_list))
9 |
--------------------------------------------------------------------------------
/Week 6/Challenge Yourself/readme.md:
--------------------------------------------------------------------------------
1 | # Week 6 Challenge Yourself
2 |
3 | [Write a program to find the missing letter given a list of increasing letters.](https://github.com/atharva-narkhede/Python/blob/main/Week%206/Challenge%20Yourself/missing_letter.py)
4 |
5 | [The Encryption Algorithm: Encrypt the given input with these steps.](https://github.com/atharva-narkhede/Python/blob/main/Week%206/Challenge%20Yourself/encryption.py)
6 |
7 | [Fun with Words "Juniors Network" Cartoon Channel is the favorite channel of all the kids in the city. As it is vacation time, the channel had introduced several new segments to engage the kids in a more creative manner. "Fun with Words" is one such activity involving English alphabets, where school kids were invited to participate.](https://github.com/atharva-narkhede/Python/blob/main/Week%206/Challenge%20Yourself/fun_with_words.py)
8 |
9 | [Balls for Challenge The Circoloco Children Carnival is the City’s largest and successful event dedicated to children and families. The main focus at the carnival is the workshop arena where kids can participate in engaging and educational activities.](https://github.com/atharva-narkhede/Python/blob/main/Week%206/Challenge%20Yourself/Balls_for_Challenge.py)
10 |
11 | [Write a program to print the abbreviation for a given sentence.](https://github.com/atharva-narkhede/Python/blob/main/Week%206/Challenge%20Yourself/abbreviation.py)
12 |
13 |
14 |
15 |
16 | Visitor count
17 |
18 |
19 |
--------------------------------------------------------------------------------
/Week 6/Skill Builder/DrNadal.py:
--------------------------------------------------------------------------------
1 | #Dr. Nadal is given a string of ‘n’ characters(S[1], S[2],...., S[n]). Then he is given Q ranges of the form [L R]. Determine of S[L], S[L+1]... S[R] is a palindrome.
2 |
3 | def check_palindrome(string,start,end):
4 | check_string = string[start:end]
5 | if(check_string[::] == check_string[::-1]):
6 | print("YES")
7 | else:
8 | print("NO")
9 |
10 | string = input()
11 | n = int(input())
12 | for i in range(n):
13 | [start,end] = [int(i) for i in input().split()]
14 | check_palindrome(string,start-1,end)
15 |
--------------------------------------------------------------------------------
/Week 6/Skill Builder/add_ing.py:
--------------------------------------------------------------------------------
1 | #Write a program to add 'ing' at the end of a given string (length should be at least 3).
2 | #If the given string already ends with 'ing' then add 'ly' instead.
3 | #If the string length of the given string is less than 3, leave it unchanged.
4 |
5 | string = input()
6 | if string.endswith('ing'):
7 | print(string + "ly")
8 | else:
9 | print(string + "ing")
10 |
--------------------------------------------------------------------------------
/Week 6/Skill Builder/bowman.py:
--------------------------------------------------------------------------------
1 | #Bowman planned a vacation to Alphabet Land. He had to solve a problem to enter Alphabet Land.
2 | #He was given N recipes made up of lower case English alphabets. The recipes were indexed from 1 to N. R[1], R[2], ….., R[N].
3 | #He had to group identical recipes and put them into bags. Help Bowman print the indices of the recipes in each bag.
4 |
5 |
6 | n = int(input())
7 | recipies_list = []
8 | for i in range(n):
9 | recipies_list.append(input())
10 | bags = len(set(recipies_list))
11 | sorted_recipies = sorted(set(recipies_list))
12 | print(bags)
13 | for recipie in sorted_recipies:
14 | for i in range(n):
15 | if recipie == recipies_list[i]:
16 | print(i+1,end = " ")
17 | print()
18 |
--------------------------------------------------------------------------------
/Week 6/Skill Builder/dollar.py:
--------------------------------------------------------------------------------
1 | #Write a Python program to get a string from a given string where all occurrences of its first char have been changed to '$', except the first char itself.
2 | string = input()
3 | char = string[0]
4 | result_string = char + string[1:].replace(char,'$')
5 | print(result_string)
6 |
--------------------------------------------------------------------------------
/Week 6/Skill Builder/duplicate_String.py:
--------------------------------------------------------------------------------
1 | #Write a program that takes a string, and returns a new string with any duplicate consecutive letters removed.
2 |
3 | string = input()
4 | result_string = ""
5 | for char in string:
6 | if char not in result_string:
7 | result_string += char
8 | print(result_string)
9 |
--------------------------------------------------------------------------------
/Week 6/Skill Builder/generate_OTP.py:
--------------------------------------------------------------------------------
1 | #Write a program to obtain an integer from the user and generate the OTP using the below steps.
2 | #1.separate digits which are in odd place index (index starts from 0)
3 | #2.square those numbers
4 | #3. Return the first 4 digits.
5 |
6 |
7 | input_integer = input()
8 | seperate_odd = []
9 | for i in range(len(input_integer)):
10 | if i % 2 != 0:
11 | seperate_odd.append(int(input_integer[i]))
12 | square_num = ""
13 | for i in seperate_odd:
14 | square_num += str(i**2)
15 | print(square_num[:4])
16 |
--------------------------------------------------------------------------------
/Week 6/Skill Builder/grammatical.py:
--------------------------------------------------------------------------------
1 | #A string S is passed as the input. The program must print the number of articles in S.
2 | #The string S passed as the input need not be correct grammatically.
3 |
4 | s=input()
5 | s=s.lower()
6 | s=s.split()
7 | for i in range(0,len(s)):
8 | s[i]="".join(e for e in s[i] if e.isalnum())
9 | print(s.count("a")+s.count("an")+s.count("the"))
10 |
--------------------------------------------------------------------------------
/Week 6/Skill Builder/minimum_dist_w1_w2.py:
--------------------------------------------------------------------------------
1 | #A string S is passed as the input. Two words W1 and W2, which are present in the string S are also passed as the input. The program must find the minimum distance D between W1 and W2 in S (in forward or reverse order) and print D as the output.
2 |
3 |
4 | s=input().split()
5 | w1=input().strip()
6 | w2=input().strip()
7 | mi=len(s)
8 | for i in range(0,len(s)):
9 | if s[i]==w1:
10 | for j in range(0,len(s)):
11 | if s[j]==w2 and mi>abs(i-j) and i!=j:
12 | mi=abs(i-j)
13 | print(mi)
14 |
--------------------------------------------------------------------------------
/Week 6/Skill Builder/permutation.py:
--------------------------------------------------------------------------------
1 | #Write a program to find all permutations of a string.
2 | def toString(List):
3 | return ''.join(List)
4 |
5 | def permute(a,l,r):
6 | if l == r:
7 | print(toString(a))
8 | else:
9 | for i in range(l,r+1):
10 | a[l],a[i] = a[i],a[l]
11 | permute(a,l+1,r)
12 | a[l],a[i] = a[i],a[l]
13 |
14 | input_string = input()
15 | n = len(input_string)
16 | a = list(input_string)
17 | permute(a,0,n-1)
18 |
--------------------------------------------------------------------------------
/Week 6/Skill Builder/readme.md:
--------------------------------------------------------------------------------
1 | # Week 6 Skill Builder
2 |
3 | [Write a program to find all permutations of a string.](https://github.com/atharva-narkhede/Python/blob/main/Week%206/Skill%20Builder/permutation.py)
4 |
5 | [A string S is passed as the input. The program must print the number of articles in S. The string S passed as the input need not be correct grammatically.](https://github.com/atharva-narkhede/Python/blob/main/Week%206/Skill%20Builder/grammatical.py)
6 |
7 | [Dr. Nadal is given a string of ‘n’ characters(S[1], S[2],...., S[n]). Then he is given Q ranges of the form [L R]. Determine of S[L], S[L+1]... S[R] is a palindrome.](https://github.com/atharva-narkhede/Python/blob/main/Week%206/Skill%20Builder/DrNadal.py)
8 |
9 | [Write a program to obtain an integer from the user and generate the OTP using the below steps.](https://github.com/atharva-narkhede/Python/blob/main/Week%206/Skill%20Builder/generate_OTP.py)
10 |
11 | [Write a Python program to get a string from a given string where all occurrences of its first char have been changed to '$', except the first char itself.](https://github.com/atharva-narkhede/Python/blob/main/Week%206/Skill%20Builder/dollar.py)
12 |
13 | [Write a program that takes a string, and returns a new string with any duplicate consecutive letters removed.](https://github.com/atharva-narkhede/Python/blob/main/Week%206/Skill%20Builder/duplicate_String.py)
14 |
15 | [Write a program to add 'ing' at the end of a given string (length should be at least 3). If the given string already ends with 'ing' then add 'ly' instead. If the string length of the given string is less than 3, leave it unchanged.](https://github.com/atharva-narkhede/Python/blob/main/Week%206/Skill%20Builder/add_ing.py)
16 |
17 | [A string S is passed as the input. Two words W1 and W2, which are present in the string S are also passed as the input. The program must find the minimum distance D between W1 and W2 in S (in forward or reverse order) and print D as the output.](https://github.com/atharva-narkhede/Python/blob/main/Week%206/Skill%20Builder/minimum_dist_w1_w2.py)
18 |
19 | [Bowman planned a vacation to Alphabet Land. He had to solve a problem to enter Alphabet Land. He was given N recipes made up of lower case English alphabets. The recipes were indexed from 1 to N. R[1], R[2], ….., R[N]. He had to group identical recipes and put them into bags. Help Bowman print the indices of the recipes in each bag.](https://github.com/atharva-narkhede/Python/blob/main/Week%206/Skill%20Builder/bowman.py)
20 |
21 | [Write a Python program to find the first appearance of the substring 'not' and 'poor' from a given string, if 'not' follows the 'poor', replace the whole 'not'...'poor' substring with 'good'. Return the resulting string.](https://github.com/atharva-narkhede/Python/blob/main/Week%206/Skill%20Builder/substring_not_poor.py)
22 |
23 |
24 |
25 |
26 |
27 | Visitor count
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/Week 6/Skill Builder/substring_not_poor.py:
--------------------------------------------------------------------------------
1 | #Write a Python program to find the first appearance of the substring 'not' and 'poor' from a given string, if 'not' follows the 'poor', replace the whole 'not'...'poor' substring with 'good'. Return the resulting string
2 |
3 |
4 | def get_result(string):
5 | if string.find("not") != -1:
6 | start = string.find("not")
7 | end = string.find("poor",start,len(string))
8 | end += 4
9 | result_string = string[:start] + "good" + string[end:]
10 | return result_string
11 | else:
12 | return string
13 |
14 | string = input()
15 | print(get_result(string))
16 |
17 |
--------------------------------------------------------------------------------
/Week 7/Challenge Yourself/Best_Mobile_Plan.py:
--------------------------------------------------------------------------------
1 | #Best Mobile Plan - St. Patrick Convent organizes a project exhibition "Innovative Minds" every year with an objective to provide the platform and unleash the potential of the students by showcasing their innovative projects.
2 |
3 | def printPlanDetails(a, b, c):
4 | A, B = 0, 0
5 | if a > 100:
6 | A = float((a-100)*0.25) + float(b*0.15)+float(c*0.20)
7 | else:
8 | A = float(b*0.15) + float(c*0.20)
9 |
10 | if a > 250:
11 | B = float((a-250)*0.45)+float(b*0.35)+float(c*0.25)
12 | else:
13 | B = float(b*0.35)+float(c*0.25)
14 | A = round(A, 2)
15 | B = round(B, 2)
16 | print('Plan A costs %.2f' % A)
17 | print('Plan B costs %.2f' % B)
18 | if A > B:
19 | print('Plan B is cheapest')
20 | elif A < B:
21 | print('Plan A is cheapest')
22 | else:
23 | print('Plan A and B are the same price')
24 |
25 |
26 | a = int(input())
27 | b = int(input())
28 | c = int(input())
29 | printPlanDetails(a, b, c)
30 |
--------------------------------------------------------------------------------
/Week 7/Challenge Yourself/Recreation_Fair.py:
--------------------------------------------------------------------------------
1 | #Recreation Fair - The Warner's Club arranged for a Recreation Fair for kids and adults for the winter season ahead. The Club offered outdoor activities for adults like hiking, cycling, power soccer and indoor activities like chess, carom and card games for kids below 10 years. Gary and Dory accompanied their parents for the fair and wanted to play the cricket collectible card game as they are crazy about the collectible cards.
2 | # You are using Python
3 | import math
4 | def hcf(a,b):
5 | if(a
14 | Visitor count
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Week 7/Challenge Yourself/sum_of_series.py:
--------------------------------------------------------------------------------
1 | # You are using Python
2 | N=int(input())
3 | def findSum(N):
4 | sumn=0
5 | for i in range(0,N+1):
6 | sumn+=(2**i)
7 | return int(sumn)
8 | print(findSum(N))
--------------------------------------------------------------------------------
/Week 7/Skill Builder/Best Programmer Baldwin High School.py:
--------------------------------------------------------------------------------
1 | #Best Programmer
2 | #Baldwin High School's Best Programmer Contest is organized today and the contest hones the students coding skills by making them solve different challenges. Based on the speed and accuracy with which the students finish the challenges, the Event coordinators will rank the participants and reward them. The entry level challenge was just one problem which the students has to program for. The problem reads like: A positive integer, n, is said to be perfect if the sum of its proper divisors equals the number itself. (Proper divisors include 1 but not the number itself.) If this sum is less than n, the number is deficient, and if the sum is greater than n, the number is abundant. The Event coordinators wanted to prepare the answer key for all the problems given in the contest so as to evaluate the submissions of the participants. Write a program using functions that reads a positive integer, determines if the integer is perfect, abundant or deficient and outputs the number along with its classification.
3 |
4 |
5 |
6 | def check_num(n):
7 | sum=0
8 | for i in range(1,n):
9 | if n%i==0:
10 | sum+=i
11 |
12 | if(sum==n):
13 | return 0
14 | elif sum
23 | Visitor count
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Week 8/Challenge Yourself/capitalize.py:
--------------------------------------------------------------------------------
1 | #Write a numpy program to capitalize the first letter, lower case, upper case and swap case of all the elements of a given array.
2 | import numpy as np
3 | word_list = np.array(input().split())
4 | print(np.char.capitalize(word_list))
5 | print(np.char.lower(word_list))
6 | print(np.char.upper(word_list))
7 | print(np.char.swapcase(word_list))
8 |
--------------------------------------------------------------------------------
/Week 8/Challenge Yourself/common_unique.py:
--------------------------------------------------------------------------------
1 | #Write a python program to get the common unique items between two arrays sorted in ascending order using numpy function.
2 | import numpy as np
3 | arr1 = np.array(list(map(int,input().split())))
4 | arr2 = np.array(list(map(int,input().split())))
5 | arr1 = np.unique(arr1)
6 | arr2 = np.unique(arr2)
7 | common_arr = np.intersect1d(arr1,arr2)
8 | print(np.sort(common_arr))
9 |
--------------------------------------------------------------------------------
/Week 8/Challenge Yourself/floor_ceiling_truncate.py:
--------------------------------------------------------------------------------
1 | #Write a numpy program to get the floor, ceiling and truncated values of the elements of a numpy array.
2 | import numpy as np
3 | array = np.array([float(i) for i in input().split(" ")])
4 | print(np.floor(array))
5 | print(np.ceil(array))
6 | print(np.trunc(array))
7 |
--------------------------------------------------------------------------------
/Week 8/Challenge Yourself/readme.md:
--------------------------------------------------------------------------------
1 | # Week 8 Challenge Yourself
2 |
3 | [Write a numpy program to capitalize the first letter, lower case, upper case and swap case of all the elements of a given array.](https://github.com/atharva-narkhede/Python/blob/main/Week%208/Challenge%20Yourself/capitalize.py)
4 |
5 | [Write a numpy program to get the floor, ceiling and truncated values of the elements of a numpy array.](https://github.com/atharva-narkhede/Python/blob/main/Week%208/Challenge%20Yourself/floor_ceiling_truncate.py)
6 |
7 |
8 | [Write a python program to compute the determinant of a square array using Numpy function.](https://github.com/atharva-narkhede/Python/blob/main/Week%208/Challenge%20Yourself/square_numpy.py)
9 |
10 |
11 | [Write a python program to get the common unique items between two arrays sorted in ascending order using numpy function.](https://github.com/atharva-narkhede/Python/blob/main/Week%208/Challenge%20Yourself/common_unique.py)
12 |
13 |
14 | [Write a python program to reverse the columns of a 2D array (mXn) using numpy.](https://github.com/atharva-narkhede/Python/blob/main/Week%208/Challenge%20Yourself/reverse2D.py)
15 |
16 |
17 |
18 |
19 | Visitor count
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Week 8/Challenge Yourself/reverse2D.py:
--------------------------------------------------------------------------------
1 | #Write a python program to reverse the columns of a 2D array (mXn) using numpy.
2 | import numpy as np
3 | row = int(input())
4 | col = int(input())
5 | rows = []
6 | print("[",end="")
7 | for i in range(row):
8 | print(np.flip(np.array(input().split())),end="")
9 | if i != row - 1:
10 | print()
11 | print("]")
12 |
13 |
--------------------------------------------------------------------------------
/Week 8/Challenge Yourself/square_numpy.py:
--------------------------------------------------------------------------------
1 | #Write a python program to compute the determinant of a square array using Numpy function.
2 | import numpy as np
3 | n = int(input())
4 | m_list = []
5 | for i in range(n):
6 | inp = [int(i) for i in input().split()]
7 | m_list.append(inp)
8 | twod_array = np.array(m_list)
9 | det = np.linalg.det(twod_array)
10 | print(det)
11 |
--------------------------------------------------------------------------------
/Week 8/Skill Builder/common_unique_items.py:
--------------------------------------------------------------------------------
1 | #Write a python program to get the common unique items between two arrays sorted in ascending order using numpy function.
2 |
3 | import numpy as np
4 | a = list(map(int, input().split()))
5 | b = list(map(int, input().split()))
6 | print(np.intersect1d(a,b))
7 |
--------------------------------------------------------------------------------
/Week 8/Skill Builder/extract_email.py:
--------------------------------------------------------------------------------
1 | #Write a program to extract all mail id’s from the given input string. User must get dynamic input.
2 | #If the string does not contain any mail id's then display 'Mail id is not present' .
3 |
4 | import re
5 |
6 | my_str = str(input())
7 | emails = re.findall("([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+)", my_str)
8 | if emails:
9 | for mail in emails:
10 | print(mail)
11 | else:
12 | print("Mail id is not present")
13 |
--------------------------------------------------------------------------------
/Week 8/Skill Builder/extract_odd_number.py:
--------------------------------------------------------------------------------
1 | #Write a program to extract all odd number from a numpy array using numpy module.
2 |
3 | # You are using Python
4 | import numpy as np
5 |
6 | inp=input().split()
7 |
8 | arr=np.array(inp,int)
9 |
10 | print(arr[arr%2==1])
11 |
--------------------------------------------------------------------------------
/Week 8/Skill Builder/extract_the_user_id.py:
--------------------------------------------------------------------------------
1 | #Write a Program to extract the user id, domain name and suffix from the following email addresses.
2 |
3 | import re
4 |
5 | emails=input()
6 | pattern = r'(\w+)@([A-Z0-9]+)\.([A-Z]{2,4})'
7 | result=re.findall(pattern,emails,flags=re.I)
8 | for i in result:
9 | print(*i)
10 |
--------------------------------------------------------------------------------
/Week 8/Skill Builder/indices_of_sorted_elements.py:
--------------------------------------------------------------------------------
1 | #Write a python program to get the indices of the sorted elements of a given array using Numpy function.
2 |
3 |
4 | import numpy as np
5 | a=input().split()
6 | arr=np.array(a,int)
7 | i =np.argsort(arr)
8 | print(i)
9 |
--------------------------------------------------------------------------------
/Week 8/Skill Builder/nXn_matrix.py:
--------------------------------------------------------------------------------
1 | #Write a NumPy program to create a nXn matrix and fill it with a checkerboard pattern.
2 |
3 |
4 | # You are using Python
5 | import numpy as np
6 | n=int(input())
7 | x=np.zeros((n,n),dtype=int)
8 | x[1::2,::2]=1
9 | x[::2,1::2]=1
10 |
11 | print(x)
12 |
--------------------------------------------------------------------------------
/Week 8/Skill Builder/nth_repetition.py:
--------------------------------------------------------------------------------
1 | #Write a python program to find the index of nth repetition of an item k in an array using numpy function.
2 |
3 | import numpy as np
4 |
5 | a=input().split()
6 | k=int(input())
7 | n=int(input())
8 |
9 | arr=np.array(a,int)
10 |
11 | print(np.where(arr==k)[0][n-1])
12 |
--------------------------------------------------------------------------------
/Week 8/Skill Builder/parse_the_given_record.py:
--------------------------------------------------------------------------------
1 | #Write a program to parse the given records and display in the given format
2 | #714016104004^AAA^#COIMBATORE^9876543213
3 | #714016104002^ABC^#MADRAS^9877543213
4 | #714016104003^XYC^9897543215
5 | #714016104003^#ERODE
6 |
7 |
8 |
9 | import re
10 | t =int(input())
11 | d,l,l1,l2={},[],[],[]
12 | d1={}
13 | for n in range(t):
14 | s=input()
15 | m=len(s.split('^'))
16 | for j in s.split('^'):
17 | if re.match("^[7]",j):
18 | a=j
19 | elif re.findall("^#[a-zA-Z]+",j):
20 | d['address']=j
21 | elif re.findall("^[a-zA-Z].+",j):
22 | d['name']=j
23 | elif re.findall("^[7|8|9][0-9]{9}$",j):
24 | d['mobile']=j
25 | if a not in d1:
26 | d1[a]=d
27 | else:
28 | d1[a].update(d)
29 | d={}
30 | for i,j in d1.items():
31 | if m
26 | Visitor count
27 |
28 |
29 |
--------------------------------------------------------------------------------
/Week 8/Skill Builder/reverse_2D_array.py:
--------------------------------------------------------------------------------
1 | #Write a python program to reverse the rows of a 2D array (mXn) using numpy.
2 |
3 | import numpy as np
4 |
5 | #User input
6 |
7 | m = int(input())
8 | n=int(input())
9 |
10 | list_array=[]
11 |
12 | for i in range(0,m):
13 | lst= input().split()
14 | list_array.append(lst)
15 |
16 | arr = np.array(list_array)
17 | print(arr[::-1])
18 |
--------------------------------------------------------------------------------
/Week 8/Skill Builder/trigo_maths.py:
--------------------------------------------------------------------------------
1 | #Write a Python function that evaluates the mathematical functions f(x)=cos(2x), f′(x)=−2sin(2x), and f′′(x)=−4cos(2x) for given value of x.
2 |
3 | from math import sin, cos, pi
4 |
5 | def deriv2(x):
6 | return cos(2*x), -2*sin(2*x), -4*cos(2*x)
7 | x=float(input())
8 | f, df, d2f = deriv2(x)
9 | print(f,df,d2f)
10 |
--------------------------------------------------------------------------------
/Week 9/Challenge Yourself/combine_lines.py:
--------------------------------------------------------------------------------
1 | #Write a python program to combine each line from first file(input1.txt) and the corresponding line in second file(input2.txt).
2 | #Store the result in file output.txt
3 |
4 |
5 |
6 | fh1 = open("input1.txt")
7 | fh2 = open("input2.txt")
8 | fh3 = open("output.txt","w")
9 | for line1, line2 in zip(fh1, fh2):
10 | str=line1+line2
11 | fh3.write(str)
12 | fh1.close()
13 | fh2.close()
14 | fh3.close()
15 |
--------------------------------------------------------------------------------
/Week 9/Challenge Yourself/count_the_frequency.py:
--------------------------------------------------------------------------------
1 | #Write a Python program to count the frequency of words in a file and display it in the console.
2 |
3 | file=open("input.txt","r+")
4 | wordcount={}
5 |
6 | for word in file.read().split():
7 | if word not in wordcount:
8 | wordcount[word] = 1
9 | else:
10 | wordcount[word] += 1
11 |
12 | for k,v in sorted(wordcount.items()):
13 | print (k, v)
14 |
--------------------------------------------------------------------------------
/Week 9/Challenge Yourself/file_ascending_order.py:
--------------------------------------------------------------------------------
1 | #File Ascending Order
2 | #Consider a input file "numbers.txt" with integer values. Write a program to Open the file and sort the content of the file in ascending order.
3 |
4 | file = open("numbers.txt", "r")
5 | numbers = []
6 |
7 | for line in file:
8 | numbers.append(int(line))
9 |
10 | numbers.sort()
11 | print(numbers)
12 | file.close()
13 |
--------------------------------------------------------------------------------
/Week 9/Challenge Yourself/number_of_lines.py:
--------------------------------------------------------------------------------
1 | #Number Of Lines in the file
2 | #Write the program to open the file and read the content to count the number of lines.
3 |
4 | file = open("input1.txt", "r")
5 | count =0
6 | for line in file:
7 | count =count+1
8 |
9 | print(count)
10 | file.close()
11 |
--------------------------------------------------------------------------------
/Week 9/Challenge Yourself/readme.md:
--------------------------------------------------------------------------------
1 | # Week 9 Challenge Yourself
2 |
3 | [Write a python program to combine each line from first file(input1.txt) and the corresponding line in second file(input2.txt). Store the result in file output.txt](https://github.com/atharva-narkhede/Python/blob/main/Week%209/Challenge%20Yourself/combine_lines.py)
4 |
5 | [Sum of the Integers in the file Consider an input file "numbers.txt" with integer values. Write a program to open the file and read the content to find the sum of all values in the file.](https://github.com/atharva-narkhede/Python/blob/main/Week%209/Challenge%20Yourself/sum_of_integers.py)
6 |
7 | [Number Of Lines in the file Write the program to open the file and read the content to count the number of lines.](https://github.com/atharva-narkhede/Python/blob/main/Week%209/Challenge%20Yourself/number_of_lines.py)
8 |
9 | [File Ascending Order Consider a input file "numbers.txt" with integer values. Write a program to Open the file and sort the content of the file in ascending order.](https://github.com/atharva-narkhede/Python/blob/main/Week%209/Challenge%20Yourself/file_ascending_order.py)
10 |
11 | [Write a Python program to count the frequency of words in a file and display it in the console.](https://github.com/atharva-narkhede/Python/blob/main/Week%209/Challenge%20Yourself/count_the_frequency.py)
12 |
13 |
14 |
15 | Visitor count
16 |
17 |
18 |
--------------------------------------------------------------------------------
/Week 9/Challenge Yourself/sum_of_integers.py:
--------------------------------------------------------------------------------
1 | #Sum of the Integers in the file
2 | #Consider an input file "numbers.txt" with integer values. Write a program to open the file and read the content to find the sum of all values in the file.
3 |
4 | file = open("numbers.txt", "r")
5 | numbers = []
6 |
7 | for line in file:
8 | numbers.append(int(line))
9 |
10 | print(sum(numbers))
11 | file.close()
12 |
--------------------------------------------------------------------------------
/Week 9/Skill Builder/Maximum_and_Minimum.py:
--------------------------------------------------------------------------------
1 | #Maximum and Minimum: Write a program to obtain an integer array and write them to a file named "input.txt". Find the maximum and minimum elements.
2 |
3 |
4 | file = open("input.txt", "r")
5 | numbers = []
6 | for line in file:
7 | numbers.append(int(line))
8 | print(max(numbers))
9 | print(min(numbers))
10 |
11 |
--------------------------------------------------------------------------------
/Week 9/Skill Builder/accept_file_name.py:
--------------------------------------------------------------------------------
1 | #Accept a file name from the user and perform the following operations
2 | #1) Print the last line of the file in upper case
3 | #2) Print the number of words and number of characters in the file
4 | #3) Write the maximum times occurring word in the file with its count.
5 |
6 | fin = open(filename, 'r')
7 | lines = fin.read()
8 | lines_lst = lines.rstrip().split('\n')
9 | print(lines_lst[-1].upper())
10 | print(len(lines.split()), len(lines))
11 |
12 | maxct = 0
13 | maxwrd = ''
14 | lst = lines.split()
15 | for wrd in lst:
16 | if lst.count(wrd) > maxct:
17 | maxct = lst.count(wrd)
18 | maxwrd = wrd
19 | print(maxwrd, maxct)
20 |
--------------------------------------------------------------------------------
/Week 9/Skill Builder/class_representative.py:
--------------------------------------------------------------------------------
1 | #The class representative has asked every student in the class to enter their rollno, name and cgpa in google word document.
2 | #The students have filled the information in single rows, but in random order in a file called student.txt.
3 | #The information has to be read , sorted based on rollno and then written in a new file ‘sortedstudent.txt’ .
4 | #If input text file contains rows of information separated by the character ‘~’ as shown below:
5 |
6 |
7 | def my_sort(line):
8 | line_fields = line.strip().split('~')
9 | roll_no = line_fields[0]
10 | return roll_no
11 |
12 |
13 | fp = open('student.txt')
14 | contents = fp.readlines()
15 | contents.sort(key=my_sort)
16 | out_file = open("sortedstudent.txt", "w")
17 | for line in contents:
18 | out_file.write(line)
19 | out_file = open("sortedstudent.txt", "r")
20 | for line in out_file:
21 | print(line)
22 | fp.close()
23 |
--------------------------------------------------------------------------------
/Week 9/Skill Builder/compare&print_common_content.py:
--------------------------------------------------------------------------------
1 | #Write a program to compare two files and print the common contents in them.
2 |
3 |
4 | file_1 = open('input1.txt', 'r')
5 | file_2 = open('input2.txt', 'r')
6 |
7 | file_1_line = file_1.readline()
8 | file_2_line = file_2.readline()
9 |
10 |
11 | line_no = 1
12 |
13 | print()
14 |
15 | with open('input1.txt') as file1:
16 | with open('input2.txt') as file2:
17 | same = set(file1).intersection(file2)
18 | same = sorted(same)
19 | for line in same:
20 | print(line, end='')
21 |
--------------------------------------------------------------------------------
/Week 9/Skill Builder/count_char_spaces_words.py:
--------------------------------------------------------------------------------
1 | #Write a program that will count the number of characters, spaces, words, and lines in a file. Words are separated by a white space character.
2 |
3 | file=open("input.txt","r")
4 | text = file.read()
5 | space=dig=alph=charc =words= 0
6 | lines=0
7 | for i in text:
8 | if (i == " "):
9 | space += 1
10 | elif (i.isalpha()):
11 | alph +=1
12 | else:
13 | charc +=1
14 |
15 | file.seek(0, 0)
16 | for line in file:
17 | lines = lines+1
18 |
19 | file.seek(0, 0)
20 |
21 | for line in file:
22 | wordslist = line.split()
23 | words = words + len(wordslist)
24 |
25 | print("Alphabets : {}\nSpaces : {}\nWords : {}\nLines : {}".format(alph, space, words, lines))
26 |
--------------------------------------------------------------------------------
/Week 9/Skill Builder/count_frequency.py:
--------------------------------------------------------------------------------
1 | #Write a program to count frequency of characters in a given file
2 |
3 |
4 | import collections
5 |
6 | file = open('sample.txt', 'w')
7 | s = input()
8 |
9 | file.write(s)
10 | file.close()
11 | with open('sample.txt', 'r') as info:
12 | count = collections.Counter(info.read())
13 |
14 | for i in sorted(count):
15 | print((i, count[i]), end=" ")
16 |
17 |
18 | file = open('sample.txt', 'r')
19 | data = file.read()
20 |
21 | file.close()
22 |
--------------------------------------------------------------------------------
/Week 9/Skill Builder/flowers.py:
--------------------------------------------------------------------------------
1 | #Assume a text file contains a flower name in each row. Read the contents of the file and display the flower names in sorted order (ascending)
2 |
3 |
4 | file = open("flowers.txt", "r")
5 | flowers = []
6 | for line in file:
7 | flowers.append(line.rstrip('\n'))
8 | flowers.sort()
9 | file.close()
10 | for ele in flowers:
11 | print(ele)
12 |
--------------------------------------------------------------------------------
/Week 9/Skill Builder/readme.md:
--------------------------------------------------------------------------------
1 | # Week 9 Skill Builder
2 |
3 | [Write a program to count frequency of characters in a given file](https://github.com/atharva-narkhede/Python/blob/main/Week%209/Skill%20Builder/count_frequency.py)
4 |
5 | [A university posts its employee salary at salary.txt. Each line in the file consists of faculty first name, last name, designation and salary.](https://github.com/atharva-narkhede/Python/blob/main/Week%209/Skill%20Builder/university_employee.py)
6 |
7 | [Write a program to compare two files and print the common contents in them.](https://github.com/atharva-narkhede/Python/blob/main/Week%209/Skill%20Builder/compare%26print_common_content.py)
8 |
9 | [Accept a file name from the user and perform the following operations 1) Print the last line of the file in upper case 2) Print the number of words and number of characters in the file 3) Write the maximum times occurring word in the file with its count.](https://github.com/atharva-narkhede/Python/blob/main/Week%209/Skill%20Builder/accept_file_name.py)
10 |
11 | [Maximum and Minimum: Write a program to obtain an integer array and write them to a file named "input.txt". Find the maximum and minimum elements.](https://github.com/atharva-narkhede/Python/blob/main/Week%209/Skill%20Builder/Maximum_and_Minimum.py)
12 |
13 | [Write a program that replaces text in a file. Your program should prompt the user to enter a filename, an old string, and a new string. After replacing every occurrence of the string it should print the modified file contents on the screen. Here is a example. test.txt (filename)](https://github.com/atharva-narkhede/Python/blob/main/Week%209/Skill%20Builder/text_in_file.py)
14 |
15 | [Assume a text file contains a flower name in each row. Read the contents of the file and display the flower names in sorted order (ascending)](https://github.com/atharva-narkhede/Python/blob/main/Week%209/Skill%20Builder/flowers.py)
16 |
17 | [The class representative has asked every student in the class to enter their rollno, name and cgpa in google word document. The students have filled the information in single rows, but in random order in a file called student.txt. The information has to be read , sorted based on rollno and then written in a new file ‘sortedstudent.txt’ . If input text file contains rows of information separated by the character ‘~’ as shown below:](https://github.com/atharva-narkhede/Python/blob/main/Week%209/Skill%20Builder/class_representative.py)
18 |
19 | [Write a program that will count the number of characters, spaces, words, and lines in a file. Words are separated by a white space character.](https://github.com/atharva-narkhede/Python/blob/main/Week%209/Skill%20Builder/count_char_spaces_words.py)
20 |
21 | [You are using a program to assist in the representative selection in your class. Three persons are interested in contesting for the post. Each person is given a nomination id like ‘10’,’20’,’30’. Every student in your class enters only the nomination id in the system. ](https://github.com/atharva-narkhede/Python/blob/main/Week%209/Skill%20Builder/representative_selection.py)
22 |
23 |
24 |
25 | Visitor count
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Week 9/Skill Builder/representative_selection.py:
--------------------------------------------------------------------------------
1 | #You are using a program to assist in the representative selection in your class.
2 | #Three persons are interested in contesting for the post. Each person is given a nomination id like ‘10’,’20’,’30’.
3 | #Every student in your class enters only the nomination id in the system.
4 |
5 | inp_file = open("election.txt", "w")
6 |
7 | nom_id = input()
8 |
9 | while(nom_id != 'end'):
10 | inp_file.write(nom_id)
11 | inp_file.write("\n")
12 | nom_id = input()
13 |
14 | inp_file = open("election.txt", "r")
15 | contents = inp_file.readlines()
16 |
17 | roll_10_count = contents.count("10\n")
18 | roll_20_count = contents.count("20\n")
19 | roll_30_count = contents.count("30\n")
20 |
21 | inp_file = open("election.txt", "a")
22 |
23 | inp_file.write("10 ")
24 | inp_file.write(str(roll_10_count))
25 | inp_file.write('\n')
26 | inp_file.write("20 ")
27 | inp_file.write(str(roll_20_count))
28 | inp_file.write('\n')
29 | inp_file.write("30 ")
30 | inp_file.write(str(roll_30_count))
31 |
32 | inp_file= open("election.txt","r")
33 | for line in inp_file:
34 | print(line)
35 |
--------------------------------------------------------------------------------
/Week 9/Skill Builder/text_in_file.py:
--------------------------------------------------------------------------------
1 | #Write a program that replaces text in a file. Your program should prompt the user to enter a filename, an old string, and a new string.
2 | #After replacing every occurrence of the string it should print the modified file contents on the screen. Here is a example. test.txt (filename)
3 |
4 | filename = input()
5 | old_string = input()
6 | new_string = input()
7 | inp_file = open(filename, "r")
8 | out_file = open("result.txt", "w")
9 | for line in inp_file:
10 | out_file.write(line.replace(old_string, new_string))
11 | out_file = open("result.txt", "r")
12 | for line in out_file:
13 | print(line)
14 | inp_file.close()
15 | out_file.close()
16 |
--------------------------------------------------------------------------------
/Week 9/Skill Builder/university_employee.py:
--------------------------------------------------------------------------------
1 | #A university posts its employee salary at salary.txt. Each line in the file consists of faculty first name, last name, designation and salary.
2 | #The columns are separated by a space.
3 | #Write a program to display the total salary and the average salary for assistant professors, associate professors, professors respectively.
4 | #Some sample lines in the file is shown below.
5 | #Deepak Sharma Professor 125000
6 | #Hemant Kumar Assistantprofessor 54000.78
7 | #Sushma Dinesh Associateprofessor 87000.50
8 |
9 |
10 | file_txt = open("salary.txt")
11 | pays = {}
12 | for line in file_txt:
13 | *name, rank, pay = line.split()
14 | pays[rank] = pays.get(rank, []) + [float(pay)]
15 | output_list = []
16 | for rank, sals in pays.items():
17 | avg = sum(sals) / len(sals)
18 | fac = []
19 | fac.append(rank.title())
20 | fac.append(sum(sals))
21 | fac.append(avg)
22 | output_list.append(fac)
23 |
24 | output_list.sort()
25 | for fac in output_list:
26 | print(*fac)
27 | file_txt.close()
28 |
--------------------------------------------------------------------------------