1. What is the result of calling the append method on a list?
2. What must be defined prior to using a method like append?
3. Explain why two lines caused an IndexError.
4. What is the result of calling the remove method on a list?
5. Give one example of a list method that requires an argument and one that does not.
6. Describe the syntax similarities and differences between using a list method like append and Python built-in functions like print.
7. Complete the function below (two lines are missing). It should prompt the user for numbers and build a list by adding one number at a time to the end of the list. The loop terminates when the user inputs the number 0
. def input_numbers():
x = 1
______________________________
x = int ( input (“Enter the first number: “))
while x != 0:
____________________________________________
x = int ( input (“Enter the next number: “))
return numbers
`Hey,
Note: If you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
1)
Append method basically adds element passed as argument at the end of list
2)
We need to define an empty list prior to using function like append
3)
Index Error is caused when we call v[I] where i>=len(v) it happens usually when we try to access the index which does not exists.
4)
remove(L) – removes the first occurrence of the specified element from the list.
Note: Brother According to Chegg's policy we are only allowed to answer first 4 part if there are many. So, I request you to post other part as separate posts
Kindly revert for any queries
Thanks.
1. What is the result of calling the append method on a list? 2. What must...
Python: Create a function count_target_in_list that takes a list of integers and the target value then counts and returns the number of times the target value appears in the list. Write program in that uses get_int_list_from_user method to get a list of 10 numbers, then calls the count_target_list method to get the count then prints the number of times the target was found in the list. def get_int_list_from_user(): lst=[] y = int(input("Enter number of numbers")) for x in range(y): lst.append(int(input("Enter...
You will turn in a java file named "MyMethods.java". It will contain one class named "MyMethods". That class will contain three methods. These methods must be in JOptionPane and must contain: getAnInt will return a value of type int, and take as an argument a string to prompt the user. The actual prompt presented to the user should include not only the string argument, but also the information that the user may press Cancel or enter an empty string to...
1. Prompt the user for one of the arithmetic operators ('op'): +, -, *,/, or ** 2. Prompt the user for two input integers ('a' and'b') 3. The input numbers can be positive or negative 4. Perform the arithmetic operation using the two input numbers 5. The first entered number ('a') is the left side, the second ('b') the right side of the operation For exponentiation, the first number is the base, the second the exponent Print (display) the following...
Step 2: Create the method specified below. static int GetValidWidth(string prompt) Input parameters prompt: message for user describing the input required Returns A non-zero width entered by the user Step 3: Create the method specified below. static int GetValidHeight(string prompt) Input parameters prompt: message for user describing the input required Returns A non-zero positive height entered by the user Step 4: Create the method specified below. static void DisplayBox(int width, int height, char fillChar) Input parameters width: width of each...
Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...
This assignment will continue our hardware store system. You will turn in a java file named "MyMethods.java". It will contain one class named "MyMethods". That class will contain three methods. These methods must be exactly as specified (including method names): getAnInt will return a value of type int, and take as an argument a string to prompt the user. The actual prompt presented to the user should include not only the string argument, but also the information that the user...
How can I modify my program to accept a list of integers (up to 20 entries) from the user into a list and prints the numbers entered by the user in ascending order, their sum and their average. The program then stops when the user inputs -100 as a number to search. #function that returns largest number def max(numOne,numTwo,numThree): if(numOne > numTwo and numOne > numThree): return numOne elif(numTwo > numOne and numTwo > numThree): return numTwo elif(numThree > numOne...
The problem is this Design a function that accepts a list as an argument and returns the largest value in the list. The function should use recursion to find the largest item. My coding so far is this def main(): # Prints the largest value in list user_input = input('Enter a list of numbers seperated by a space: ') user_list = user_input.split() print('Largest number is ', max_Number(user_list), '.') # Recursion function that finds the maximum number in a sequence of...
Write the following method to test whether the array has four consecutive numbers with the same value. public static boolean isConsecutiveFour(int[] values) Write a java test program that prompts the user to enter a series of integers and displays if the series contains four consecutive numbers with the same value. Your program should first prompt the user to enter the input size - i.e., the number of values in the series. Expected results: Enter the number of values: 7 Enter...
Write a python program: Ask for the encryption key. The key must be a list of numbers between 0 and N-1, where N is the number of entries in the key's list; for example, 5,4,3,2,1,0 has six numbers, and each digit 0-5 appears in the list. Asks for a line of text to encrypt. Use the transposition key to transpose each chunk of N letters in input text. If the input text is not a multiple of the key length,...