malikhuzaifa043

You might also like

Download as pdf
Download as pdf
You are on page 1of 10
University of Central Punjab, 6th Road, Rawalpindi Campus. CSDS4423: Programming for Big Data (Spring 2024) A#01 Issue date Due date Instructor:Engr. Jahania Usman Monday Saturday May 13 May 18 Name: Malik Huzaifa Riaz Roll No: RIF22UBSCS043 Signature: Section: _BSCS-4A {Important Notes: 1. ZERO Tolerance Policy cheating. 2. Violators may receive “F”in the course and/or will face further strict penalty. 3, Assignments may carry unequal weights. 4, Np ratekgrareallacaliompfeusroneespektive of the reason, genuine or otherwise, for plagiarism and Do not write anything below. “This cover MUST be The MTSt page OMe assignment. Submitsoft copy ofassignments, only. ‘Assignment must be submitted on the following link: https://forms.gle/OVWaRaHJDTuPEFVS7 No late assignment accepted after due date/tim« ‘Quiz date wil be same as submission date Checked by Plagiarism ures UNo % Attempted Total Marks 65 Warks Obtained ‘Submission Guidelines: Failure to follow these may VOID your assignment. aa ‘Write a Python function named rectangle_area that takes two parameters length and width and returns the area of a rectangle. Then, call this function with length=S and width=3 and print the result. def rectangle_area(length, width): return Length * width Length = 5 width = 3 area = rectangle srea(length, width) print(fThe ares of the rectengle with length (length) ond width (width) is (area ‘The area of the rectangle with length 5 and width 3 is 35, a2 Write a Python function named reverse_string that takes a string as input and returns the reverse of that string, Then, cal this function with a string of your choice a) def reverse_string(s): input_string = “hello” reversed_string = reverse_string(input_string) print(f"the reverse of the string "{input_string)’ is "{reversed_string)'. ‘The reverse of the string ‘hello’ is ‘oleh. a3 Write a Python function named count_vowels that takes a string as input and returns the count of ‘vowels (a , i, 0, u) in that string. Then, call this function with a string of your choice. def count_vowels(s): vowels = "aelouderou" count = sum(1 for char in s if char in vowels) return count Anput_string = "hello world” vowel_count = count_vowels(input_string) print(#"The number of vowels in the string "{input_string}' is (vowel_count}.") The number of vowels in the string "hello world’ is 3. aa Write a Python function named find_max that takes a list of numbers as input and returns the maximum ‘number in that list. Then, call this function with a list of numbers of your choice. def Find_max(nunbers): Af not numbers: return None max_nunbert ‘max_number = num return max_number semple_list = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] inax_nunber ~ find_max(sample list) print(#"The maximum nunber in the list (sample list) is (max_number}.") The m: imum number in the list [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5] is 9. as Write @ Python function named is_palindrome that takes a string as input and returns True ifthe string. is a palindrome (reads the same forwards and backwards), otherwise returns False. Then, call this function with a string of your choi def iz_palindrone(=): normalized s = **.join(cher.lower() for char in s if char.{selnun()) return normal: a) input_string = "A man, 2 plan, a conal, Panama” is_Anput_palindrone = is_palindrome(input_string) sed_2 == normalized 2 print(#"The string ‘(input_string)' is a palindrome: (is_input_palindrone)") ‘The string ‘A man, a plan, a canal, Panama’ iz = palindrome: True as ‘Write a Python function named is_prime that takes a positive integer as input and returns True if the number is prime, otherwise returns False. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Then, call this function with a positive integer of your choice. def is_prime(num): 46 num c= a: return False Anput_number = 17 Lz input_prime = is_prime(input_number) Af de input pris print(f*The number (input_uber) is prine.") es print(#"The number (nput_number) is not prine.") ‘The number 17 is prine a7 Write a Python function named find_common_elements that takes two lists as input and returns a new list containing the common elements between them, without duplicates. Then, call this function with ‘wo lists of your choice. def Find_comon_elenents(list1, list2): ‘comon_elenents = set(listi) & set(1ist2) return 1ist(conmon_element:) Lista = [1, 2, 3, 4, 5] List2 = [3, 4, 5, 6, 7] comon_elenents = find_comon_elements(list1, list2) print(F"The common elenents between {ist} and (1ist2) are: {common_elements}") ‘The common elements between [1, 2, 3, 4 5] and [3, 4, 5, 6 7] are: [3,4 5] as Write a Python function named generate_fibonacci that takes a positive integer n as input and returns a list containing the first n numbers in the Fibonacci sequence. The Fibonacci sequence starts with 0 and 1, and each subsequent number is the sum of the two preceding numbers. Then, cal this function with 2 positive integer n of your choice. def generate fibonacci(n): Fibonacet_sequence = (0, 1] While Len(fibonacct, sequence) < a: next _fibonacct_nunber = fibonacctsequence(-1) + fibonace!,sequence(-2) Fibonacei_sequence.append(next_fibonaces_nunber) return Fibonacci sequence|:n) n= 10 Fibonacei_sequence = generate_fibonacci(n) print(f*the First (n) numbers in the Flbonaccl sequence are: (flbonacct_ sequence”) ‘The first 10 numbers in the Fibonacci sequence are: [0, 1, 1, 2, 3, 5, 8 13, 21, 34] Q.9 Write a Python program to print the following pattern using nested loops: e) def print_pattern(rows): for i in range(1, rows + 1): for j in range(i) print(“*", end" ") print() rows = 5 print_pattern(rous) @.10 Write a Python function named merge_sorted lists that takes two sorted lists as input and returns ‘a new sorted list containing all elements from both input lists, Then, call this function with two sorted lists of your choice. 8) def merge_sorted_lists(1isti, 1ist2): merged_list = [] Lj-e0 while 4 < Len(Listt) and 3 < Len(1ist2): if Lista[i] < List2[d]: smerged_List.oppend(Iist1{4]) ise else: mmerged_List.oppend(1ist2{5]) seed merged_list.extend(list2[i:]) merged list extend(1tst2{3:]) return merged list List = [1, 3, 5, 7) 9) Ust2 = [2, 4, 6, 8, 20) smerged_list - merge sorted lists(Iisti, 1ist2) prine(#*"The merged sorted list is: (merged list)*) The merged sorted list is: [1, 2, 3, 4, 5, 6, 7, 8, % 10] ait ‘Write a Python function named max_product that takes a list of integers as input and returns the maximum product of any two numbers in the list. Then, call this function with a lst of integers of your choice. def merge sorted lists(1isti, 1ist2): merged list = () i, j-e0 while i < en(1ist1) and j < len(1ist2} if Msta[i] < list2{d]: merged _list.eppend(list1{1}) Lesa else merged _list.eppend(1ist2{j]) jera merged_list .extend(1ista[4: )) merged list .extend(1ist2(4: )) return merged list List = [1, 3, 5, 7, 9] list2 = [2, 4, 6, 8, 10] merged list ~ merge sorted lists(list1, list2) print(#"The merged sorted list is: (merged_list)") The merged sorted list is: [1, 2, 3, 4, 5+ 6 7, 8, 9 10] qaz ‘a Python program to unpack a tuple into multiple v my_tuple = (1, 2, 3) 2, bs ¢ = my tuple a3 Imagine you are working as a data scientist for a large e-commerce company. The company has collected vast amounts of customer data over the years, including purchase history, browsing behavior, demographics, and interactions with marketing campaigns. Recently, the company has been experiencing challenges in managing and analyzing this data effectively. How would you apply the three Vs of big data (Volume, Variety, and Velocity) to address the challenges faced by the e-commerce company? Provide specific strategies or approaches for each "V" that could help improve the ‘management and analysis of the company's data, Solution: 65) To manage big data challenges, the e-commerce company can scale storage, integrate diverse data sources, and utilize real-time processing. These strategies drive better insights, decision-making, and customer experiences, ensuring competitiveness. 1. Volume ‘© Data Storage and Management: Implement scalable storage solutions such as cloud-based data lakes or distributed databases to handle large volumes of data efficiently. ‘+ Data Compression and Optimization: Utilize compression techniques to reduce storage requirements without sacrificing data integrity. ‘Additionally, optimize data structures and formats for faster access and processing, ‘© Data Sampling: Employ sampling techniques to work with subsets of the data for exploratory analysis or testing algorithms before applying them to the entire dataset, ‘© Streamlining Data Pipelines: Design robust data pipelines that automate the ingestion, processing, and storage of large volumes of. data, ensuring reliability and scalability. 2. Variety ‘+ Data Integration: Integrate data from various sources such as transaction databases, customer relationship management (CRM) systems, website analytics tools, and social media platforms to create a comprehensive view of customer behavior and interactions. ‘© Data Preprocessing and Cleansing: Implement preprocessing techniques to handle diverse data formats, structures, and quality issues. This includes data cleansing, normalization, and transformation to ensure consistency and reliability. © Advanced Analytics: Utilize advanced analytics techniques such as machine learning, natural language processing (NLP), and sentiment analysis to derive insights from unstructured data sources lke customer reviews, social media posts, and product descriptions, ‘© Semantic Integration: ‘Apply semantic integration approaches to reconcile differences in data semantics across heterogeneous sources, enabling meaningful analysis and interpretation, 3. Velocity ‘+ Real-time Data Processing: Implement real-time data processing frameworks such as Apache Kafka or Apache Flink to analyze streaming data from online transactions, clickstreams, and social media interactions in near real-time, ‘© Event-driven Architecture: ‘Adopt event-driven architecture to capture and process data asynchronously, enabling timely responses to customer interactions and market trends. © Predictive Analyt Develop predictive models that leverage streaming data to anticipate customer behavior, detect anomalies, and personalize recommendations in real-time. Agile Data Analytics: Implement agile methodologies for data analytics to rapidly iterate on data analysis tasks, experiment with different models, and adapt to changing business requirements and market dynamics. By addressing the challenges posed by the three Vs of big data (Volume, Variety, and Velocity) using ‘these strategies and approaches, the e-commerce company can improve the management and analysis of ‘its vast amounts of customer data, leading to better decision-making, enhanced customer ‘experiences, and competitive advantage in the market. References [1] bttos://www.w3schools.com/pvthon/python howto reverse string.as [2]httos://ovnative.com/print-pattern-python-examples [3] https://www.geeksforgeeks.org/python-combining-two-sorted-lists [a] https://www.geeksforgeeks.org/unpacking (5) https://chatgpt.com tuple-ine

You might also like