Small Functions程序设计 写作、 辅导Java,c++

” Small Functions程序设计 写作、 辅导Java,c++Part 2: Write Small Functions / ProgramsPart 2: Write Small Functions / ProgramsInstructions[P2 Q1] Find all duplicates in a list[P2 Q2] No Repeats![P2 Q3] Adding up letters[P2 Q4] Longest consecutive sequence[P2 Q5] Testing PourInstructionsComplete the following questions.[P2 Q1] Find all duplicates in a listWrite a function find_duplicates() that takes in a list of integers from 1 to n, where n is thelength of the list. The function returns the first value that is repeated in the list.If the parameter is not a list or the Elements in the list are outside the range, return -1 . If noelements are repeated, then return 0 .RESTRICTIONSOnly allowed: variables, if statements, while loops. Functions: len() , int() , float() ,type() , isinstance() . String methods: format() . List operators and methods: create [ ] ,list() , append() . Keywords: elif , else , return , break , continue , def , self , None , try ,raise , except , finally , is , import sys . Any exception handling.Remember: Do NOT use for loops or the in keyword. Do NOT use min() / max() ,enumerate() / zip() or sorted() . Do NOT use negative indexing (e.g. ls[-1] ) or slicing (e.g.[1:] ). Do NOT use other list operations and methods. Marks will be deducted.[P2 Q2] No Repeats!Write a program which continuously asks for user input until the a repeated value is given. Theprogram should then print out Input number number is not unique! and terminate.print(find_duplicates([1, 2, 3, 2])) # 2print(find_duplicates([1, 1, 2, 2])) # 1print(find_duplicates([4, 3, 1, 2])) # 0print(find_duplicates([1, 2, 2, 0])) # -1print(find_duplicates([])) # 0print(find_duplicates((1, 2, 3))) # -1RESTRICTIONSOnly allowed: variables, if statements, while loops. Functions: len() , int() , float() ,type() , isinstance() , input() , print() . String methods: format() . List operators andmethods: create [ ] , list() , append() . Keywords: elif , else , return , break , continue ,def , None , try , raise , except , finally , is , import sys . Any exception handling.Remember: Do NOT use for loops or the in keyword. Do NOT use min() / max() ,enumerate() / zip() or sorted() . Do NOT use negative indexing (e.g. ls[-1] ) or slicing (e.g.[1:] ). Do NOT use other list Operations and methods. Marks will be deducted.[P2 Q3] Adding up lettersWrite a function word_sum() that takes in a string and returns the sum according to the followingrules:Each letter in the alphabet is given a number corresponding to their position in the alphabet,i.e. a has value 1 , b has value 2 , c has value 3 , … z has value 26 . Lettersshould be case insensitive.Numeric digits have the same value as their true numeric counterparts, i.e. 1 has value 1 ,2 has value 2 , etc.Characters which are not a letter in the alphabet and not a digit have a value of 0 .The sum to be returned should be an integer equal to sum of all the corresponding values of thecharacters. If the input is not of the correct type, raise a TypeError with the message Inputmust be a string.RESTRICTIONSOnly allowed: variables, if statements, while loops. Functions: len() , int() , float() ,type() , isinstance() . String methods: format() . List operators and methods: create [ ] ,list() , append() . Keywords: Elif , else , return , break , continue , def , self , None , try ,raise , except , finally , is , import sys . Any exception handling.$ python3 no_repeats.pyGive me an input: # aGive me an input: # bGive me an input: # 375Give me an input: # c#Give me an input: # bInput number 5 is not unique!print(word_sum(abc)) # 6print(word_sum(ab*c!)) # 6print(word_sum(123ab)) # 9print(word_sum(!@#0)) # 0print(word_sum()) # 0print(word_sum(123)) # TypeErrorRemember: Do NOT use for loops or the in keyword. Do NOT use other string or listoperations and methods. This includes, but is not limited to isalpha() , isnumeric() ,isalnum() and isdigit() . Do NOT use min() / max() , enumerate() / zip() or sorted() . DoNOT use negative indexing (e.g. ls[-1] ) or slicing (e.g. [1:] ). Marks will be deducted.[P2 Q4] Longest consecutive sequenceA consecutive sequence is one where the next number is 1 more than the previous one (e.g. 3, 4,5, 6, etc.). Write a function longest_consecutive_sequence() that takes as input a list of integersand returns the starting index of the first longest consecutive sequence.If the list value is not an integer, ignore it. If no consecutive sequence of two or greater exists or ifthe given input is not a list, return -1 .RESTRICTIONSOnly allowed: variables, if statements, while loops. Functions: len() , int() , float() ,type() , isinstance() . String methods: format() . List operators and methods: create [ ] ,list() , append() . Keywords: elif , else , return , break , continue , def , self , None , try ,raise , except , finally , is , import sys . Any exception handling.Remember: Do NOT use for loops or the in keyword. Do NOT use min() / max() ,enumerate() / zip() or sorted() . Do NOT use negative indexing (e.g. ls[-1] ) or slicing (e.g.[1:] ). Do NOT use other list operations and methods. Marks will be deducted.[P2 Q5] Testing PourWrite four good unit tests for the Pour_into() method from the Filling in Bottles question,without repeating the same style of test case. Give the inputs and expected outputs by filling inthe corresponding fields in the text file template. Also, give your reasoning for each test case inthe justification section.SCAFFOLDprint(longest_consecutive_sequence([7, 1, 2, 3, 6, 9, 2, 5, 6, 7])) # 1print(longest_consecutive_sequence([8, 4, 3, 1, 5, 6])) # 4print(longest_consecutive_sequence([9, 10, 11, 13, 14, 15, 16])) # 3print(longest_consecutive_sequence([2, a, 3, 4])) # 2print(longest_consecutive_sequence([1, 1, 1, 1, 1])) # -1print(longest_consecutive_sequence([0])) # -1TEST 1Justification:Inputs:Bottle 1 capacity:Bottle 1 current amount:Bottle 2 capacity:Bottle 2 current amount:Amount (input argument):Expected output:Bottle 1 current amount:Bottle 2 current amount:TEST 2Justification:Inputs:Bottle 1 capacity:Bottle 1 current amount:Bottle 2 capacity:Bottle 2 current amount:Amount (input argument):Expected output:Bottle 1 current amount:Bottle 2 current amount:TEST 3Justification:Inputs:Bottle 1 capacity:Bottle 1 current amount:Bottle 2 capacity:Bottle 2 current amount:Amount (input argument):Expected output:Bottle 1 current amount:Bottle 2 current amount:TEST 4Justification:Inputs:Bottle 1 capacity:Bottle 1 current amount:Bottle 2 capacity:Bottle 2 current amount:Amount (input argument):Expected output:Bottle 1 current amount:Bottle 2 current amount:请加QQ:99515681 或邮箱:99515681@qq.com WX:codehelp

添加老师微信回复‘’官网 辅导‘’获取专业老师帮助,或点击联系老师1对1在线指导