<jupyter_start><jupyter_text>---- 2.1 Problem Statement: PYTHON 1 ---- 1) Install Jupyter notebook and run the first program and share the screenshot of the output. Please find the screenshot image "Jupyter_screenshot.png" at the github URL https://github.com/sudhanshushankersingh/PYTHON-1-2-3-4-5/blob/master/Jupyter_screenshot.png 2) Write a program which will find all such numbers which are divisible by 7 but are not a multiple of 5, between 2000 and 3200 (both included). The numbers obtained should be printed in a comma-separated sequence on a single line.<jupyter_code>list = [x for x in range(2000,3201) if x%7 == 0 and x%5 !=0]
count = 0
for i in list:
    count += 1
    print(i, end="," if count < len(list) else "")<jupyter_output>2002,2009,2016,2023,2037,2044,2051,2058,2072,2079,2086,2093,2107,2114,2121,2128,2142,2149,2156,2163,2177,2184,2191,2198,2212,2219,2226,2233,2247,2254,2261,2268,2282,2289,2296,2303,2317,2324,2331,2338,2352,2359,2366,2373,2387,2394,2401,2408,2422,2429,2436,2443,2457,2464,2471,2478,2492,2499,2506,2513,2527,2534,2541,2548,2562,2569,2576,2583,2597,2604,2611,2618,2632,2639,2646,2653,2667,2674,2681,2688,2702,2709,2716,2723,2737,2744,2751,2758,2772,2779,2786,2793,2807,2814,2821,2828,2842,2849,2856,2863,2877,2884,2891,2898,2912,2919,2926,2933,2947,2954,2961,2968,2982,2989,2996,3003,3017,3024,3031,3038,3052,3059,3066,3073,3087,3094,3101,3108,3122,3129,3136,3143,3157,3164,3171,3178,3192,3199<jupyter_text>3) Write a Python program to accept the user's first and last name and then getting them printed in the the reverse order with a space between first name and last name.</font<jupyter_code>first_name = input('Please enter the first name ')
last_name = input('Please enter the last name ')
print('Name in reverse order:',last_name,first_name)<jupyter_output>Please enter the first name Sudhanshu
Please enter the last name Singh
Name in reverse order: <NAME><jupyter_text>4) Write a Python program to find the volume of a sphere with diameter 12 cm.Formula: V=4/3 * π * r 3<jupyter_code>import math
pi = math.pi
diameter = 12.0
r= diameter / 2
v = 4.0/3.0*pi* r**3
print('The volume of the sphere is:',v)<jupyter_output>The volume of the sphere is: 904.7786842338603<jupyter_text>---- 2.2. Problem Statement: PYTHON 2 ---- 1) Write a program which accepts a sequence of comma-separated numbers from console and generate a list.<jupyter_code>numbers = input("Please enter comma seperated numbers ")
generated_list = numbers.split(",")
print("Generated List: ",generated_list)<jupyter_output>Please enter comma seperated numbers 1,2,3,4,5,6,7,8,9,10
Generated List:  ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']<jupyter_text>2) Create the below pattern using nested for loop in Python.<jupyter_code># This code is flexible for any pattern and its number of max occurences. We just need to modify the values of max and
# pattern variables to change the output pattern
max = 5
pattern = "*"
for i in range(max+1):
    print(pattern*i)
    if i == max:
        for j in range(max,1,-1):
            i = i-1
            print(pattern*i)<jupyter_output>*
**
***
****
*****
****
***
**
*<jupyter_text>3) Write a Python program to reverse a word after accepting the input from the user.Sample Output:Input word: AcadGildOutput: dilGdacA<jupyter_code>input_data = input("Input word: ")
print("Output: ",input_data[::-1])<jupyter_output>Input word: AcadGild
Output:  dliGdacA<jupyter_text>4) Write a Python Program to print the given string in the format specified in the sample output.<jupyter_code>string = "WE, THE PEOPLE OF INDIA,{}having solemnly resolved to constitute India into a SOVEREIGN,{}SOCIALIST, SECULAR, DEMOCRATIC {}REPUBLIC and to secure to all its citizens"
print(string.format('\n\t','!\n\t\t','\n\t\t '))<jupyter_output>WE, THE PEOPLE OF INDIA,
	having solemnly resolved to constitute India into a SOVEREIGN,!
		SOCIALIST, SECULAR, DEMOCRATIC 
		 REPUBLIC and to secure to all its citizens<jupyter_text>---- 2.3. Problem Statement: PYTHON 3 ---- 1.1. Write a Python Program to implement your own myreduce() function which works exactly like Python's built-in function reduce()<jupyter_code>def myreduce(anyfunc, sequence):
    # Get first item in sequence and assign to result
    result = sequence[0]
    # iterate over remaining items in sequence and apply reduction function 
    for item in sequence[1:]:
        result = anyfunc(result, item)
    return result

# Testing our own myreduce() function which will return the Sum of all numbers present in the list
def sum(x,y):
    return x + y

print ("Sum on list [1,2,3,4] using custom reduce function " + str(myreduce(sum, [1,2,3,4])) )<jupyter_output>Sum on list [1,2,3,4] using custom reduce function 10<jupyter_text>1.2. Write a Python program to implement your own myfilter() function which works exactly like Python's built-in function filter()<jupyter_code>def myfilter(anyfunc, sequence):
    # Initialize empty list
    result = []
    # iterate over sequence of items in sequence and apply filter function
    for item in sequence:
        if anyfunc(item):
            result.append(item)
            # return funal output
    return result

# Testing our own myfilter() function to find and display positive numbers from a given list of numbers
def ispositive(x):
    if (x <= 0):
        return False
    else:
        return True

# Another test to find even numbers from a given list of numbers
def square(k):
    if(k%2 == 0):
        return True
    
print("Even numbers are: ",myfilter(square,[1,2,3,4,5,6,7,8,9,10]))
print("Positive numbers are: ",myfilter(ispositive,[1,-2,3,10,-10,100,-9,90,2.25]))<jupyter_output>Even numbers are:  [2, 4, 6, 8, 10]
Positive numbers are:  [1, 3, 10, 100, 90, 2.25]<jupyter_text>2. Implement List comprehensions to produce the following lists.Write List comprehensions to produce the following Lists.['A', 'C', 'A', 'D', 'G', 'I', ’L’, ‘ D’]['x', 'xx', 'xxx', 'xxxx', 'y', 'yy', 'yyy', 'yyyy', 'z', 'zz', 'zzz', 'zzzz'] ['x', 'y', 'z', 'xx', 'yy', 'zz', 'xxx', 'yyy', 'zzz', 'xxxx', 'yyyy', 'zzzz'] [[2], [3], [4], [3], [4], [5], [4], [5], [6]] [[2, 3, 4, 5], [3, 4, 5, 6], [4, 5, 6, 7], [5, 6, 7, 8]][(1, 1), (2, 1), (3, 1), (1, 2), (2, 2), (3, 2), (1, 3), (2, 3), (3, 3)]<jupyter_code>word = "ACADGILD"

letter_list = [ letters for letters in word ]
print (str(letter_list))
input_list = ['x','y','z']
output_list = [data*num for data in input_list for num in range(1,5)]
print (str(output_list))
input_list = ['x','y','z']
output_list = [num*data for num in range(1,5) for data in input_list]
print (str(output_list))
input_list = [1,2,3]
output_list = [[i+num] for i in input_list for num in range(1,4)]
print (str(output_list))
input_list = [1,2,3,4]
output_list = [[i+num for i in range(1,5)] for num in range(1,5)]
print (str(output_list))
input_list = [1,2,3]
output_list = [(num+1,i) for i in input_list for num in range(0,3)]
output_list1 = [ (b,a) for a in input_list for b in input_list]
print (str(output_list1))<jupyter_output>[(1, 1), (2, 1), (3, 1), (1, 2), (2, 2), (3, 2), (1, 3), (2, 3), (3, 3)]<jupyter_text>3. Implement a function longestWord() that takes a list of words and returns the longest one.<jupyter_code>import functools as ft
world_list = ['This','is','my','jungle']
def findLongestWord(world_list):
    output = ft.reduce(lambda x,y: x if(len(x) > len(y)) else y ,world_list)
    return output

longest_word = findLongestWord(world_list)
print("Longest word is",longest_word,"having size as",len(longest_word))<jupyter_output>Longest word is jungle having size as 6<jupyter_text>---- 2.4. Problem Statement: PYTHON 4 ---- 1.1 Write a Python Program(with class concepts) to find the area of the triangle using the below formula. area = (s*(s-a)*(s-b)*(s-c)) *** 0.5Function to take the length of the sides of triangle from user should be defined in the parent class and function to calculate the area should be defined in subclass.<jupyter_code># Parent class having a function to take the length of the sides of triangle
class Polygon:

    def __init__(self, n):
        self.number_of_sides = n

    def print_num_sides(self):
        print('There are ' + str(self.number_of_sides) + ' sides.')

# Class having a function to calculate the area
class Triangle(Polygon):

    def __init__(self, lengths_of_sides):
        Polygon.__init__(self, 3)
        self.lengths_of_sides = lengths_of_sides  # list of three numbers

    def get_area(self):
        '''return the area of the triangle using the semi-perimeter method'''
        a, b, c = self.lengths_of_sides

        # calculate the area
        s = (a + b + c) / 2
        return (s*(s-a)*(s-b)*(s-c)) ** 0.5

tri = Triangle([4, 5, 6])
print("Area of the triangle is: ",tri.get_area())<jupyter_output>Area of the triangle is:  9.921567416492215<jupyter_text>1.2 Write a function filter_long_words() that takes a list of words and an integer n and returns the list of words that are longer than n.<jupyter_code>def filter_long_words(words,n):
    output = [i for i in words if len(i) > n]
    return output

n = 4
words = ['elephant','dog','monkey','cat','butterfly','hen']
result = filter_long_words(words, n)
print(result)<jupyter_output>['elephant', 'monkey', 'butterfly']<jupyter_text>2.1 Write a Python program using function concept that maps list of words into a list of integers representing the lengths of the corresponding words.Hint: If a list [ ab,cde,erty] is passed on to the python function output should come as [2,3,4]Here 2,3 and 4 are the lengths of the words in the list.<jupyter_code>def words_to_integers(words):
    integers = []
    for i in words:
        integers.append(len(i))
    return integers

listOfWords = ['ab','cde', 'erty']
result = words_to_integers(listOfWords)
print("List of integers representing the lengths of the corresponding words are",result)<jupyter_output>List of integers representing the lengths of the corresponding words are [2, 3, 4]<jupyter_text>2.2 Write a Python function which takes a character (i.e. a string of length 1) and returns True if it is a vowel, False otherwise.<jupyter_code>def checkVowel(char):
    if char in ['a','e','i','o','u']:
        return True
    else:
        return False
charInput = 'u'
boolean = checkVowel(charInput)
if boolean:
    print("True")
else:
    print("False")<jupyter_output>True<jupyter_text>---- 2.5. Problem Statement: PYTHON 5 ---- 1. Write a function to compute 5/0 and use try/except to catch the exceptions.<jupyter_code>def testTryCatch():
    try:
        result = 5/0
    except ArithmeticError:
        print("Something went wrong while performing the mathematical operation")
    except Exception:
        print("Something went wrong. Please verify the code and input data and try again")

testTryCatch()<jupyter_output>Something went wrong while performing the mathematical operation<jupyter_text>2. Implement a Python program to generate all sentences where subject is in ["Americans", "Indians"] and verb is in ["Play", "watch"] and the object is in ["Baseball","cricket"].Hint: Subject,Verb and Object should be declared in the program as shown below.subjects=["Americans ","Indians"]verbs=["play","watch"]objects=["Baseball","Cricket"]Output should come as below:Americans play Baseball.Americans play Cricket.Americans watch Baseball.Americans watch Cricket.Indians play Baseball.Indians play Cricket.Indians watch Baseball.Indians watch Cricket.<jupyter_code>subject = ["Americans", "Indians"]
verb = ["Play", "watch"]
object = ["Baseball","cricket"]
space = " "
result = [i+space+j+space+k for i in subject for j in verb for k in object]

for r in result:
    print(r)<jupyter_output>Americans Play Baseball
Americans Play cricket
Americans watch Baseball
Americans watch cricket
Indians Play Baseball
Indians Play cricket
Indians watch Baseball
Indians watch cricket<jupyter_text>project1_Piggy_Bank: implement a small interactive application using concept learnt<jupyter_code>class PiggyBank:
    def __init__(self):
        self.balance = 0
    
    def check(self):
        return self.balance
    
    def add(self, amount):
            self.balance += amount
    
    def withdraw(self, amount):
            self.balance -= amount
            
    def takeInput(self):
        begin = input("Start or End : ")
        return begin
    
    def takeOperationInput(self):
        operation = input("Add, Withdraw or Check : ")
        return operation
    
    def start(self):
        begin = pb.takeInput()
        if begin == "Start":
            operation1 = pb.takeOperationInput()
            if operation1 == "Add":
                amount = float(input("Add Amount : "))
                if(amount == 0):
                    print("You can not place a request for zero money. Please enter a valid amount.")
                elif (amount > 0 and int(self.check()) >=0):
                    try:
                        pb.add(amount)
                        print("After adding, your updated balance is",pb.check(),"rupees")
                        print("None")
                    except ValueError:
                        print("Please enter a number value and try again")
                else:
                    print("Negative balance not allowed")
                    pb.start()
            elif operation1 == "Check":
                print("Your current balance is",pb.check(),"rupees")
                print("None")
            elif operation1 == "Withdraw":
                withdrawAmount = float(input("Winthdraw amount : "))
                if(withdrawAmount == 0):
                    print("You can not place a request for zero money. Please enter a valid amount.")
                elif (withdrawAmount > 0 and int(self.check()) > 0):
                    try:
                        pb.withdraw(withdrawAmount)
                        print("After withdrawing, your updated balance is",pb.check(),"rupees")
                        print("None")
                    except ValueError:
                        print("Please enter a number value and try again")
                else:
                    print("Negative balance not allowed")
                    pb.start()
            else:
                print("Could not understand the input. Please try again and be mindful of the case sensitiveness")
        elif begin == "End":
            print("Operation ended")
        else:
            print("Could not understand the input. Please try again and be mindful of the case sensitiveness")
        if begin != "End":
            pb.start()

pb = PiggyBank()
pb.start()<jupyter_output>Start or End : Start
Add, Withdraw or Check : Add
Add Amount : 1000
After adding, your updated balance is 1000.0 rupees
None
Start or End : Start
Add, Withdraw or Check : Withdraw
Winthdraw amount : 300
After withdrawing, your updated balance is 700.0 rupees
None
Start or End : Start
Add, Withdraw or Check : Check
Your current balance is 700.0 rupees
None
Start or End : End
Operation ended
{'fraction_non_alphanumeric': 0.12037098818976447, 'fraction_numerical': 0.060118769600320275, 'mean_word_length': 3.6677047648707566, 'pattern_counts': {'":': 6, '<': 59, '<?xml version=': 0, '>': 62, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '18', 'dir': 'jupyter-structured-clean-dedup', 'id': '482269', 'license': 'MIT', 'n_tokens_mistral': 5336, 'n_tokens_neox': 4762, 'n_words': 1624, 'path': 'Assignments_Session_1_To_Session_5 (PYTHON 1, 2, 3, 4 & 5).ipynb', 'repo_name': 'sudhanshushankersingh/PYTHON-1-2-3-4-5', 'size': '14996'}