Question

In: Computer Science

Read in user-input integers one at a time until the user types ‘q’, storing all inputs...

Read in user-input integers one at a time until the user types ‘q’, storing all inputs in a list. Then, print out the even numbers in increasing order, from smallest value to largest. Python

Solutions

Expert Solution

The indentation in the answering window sometimes disappear automatically due to some technical issue on the website, please refer to the screenshots for indentation.

If you have any queries please comment in the comments section and kindly upvote.

# initialize an empty list
li=[]
# run an infinite loop until 'q' is entered
while(True):
# input element
ele=input()
# if the input is q then break
if ele=='q':
break
# otherwise append the element to the list after type casting it to integer
else:
li.append(int(ele))
# sort the list
li.sort()
# iterate over the list
for i in range(len(li)):
# if the element in the list is even then print the element
if li[i]%2==0:
print(li[i],end=" ")


Related Solutions

Read the input one line at a time until you have read all lines. Now output...
Read the input one line at a time until you have read all lines. Now output these lines in the opposite order from which they were read.. import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class Part12 {       /**    * Your code goes here - see Part0 for an example    * @param r the reader to read from    * @param w the writer to write to    * @throws IOException...
Read three integers from user input.
Read three integers from user input.
Write a program that will read in from input file one line at a time until...
Write a program that will read in from input file one line at a time until end of file and output the number of words in the line and the number of occurrences of each letter. Define a word to be any string of letters that is delimited at each end by either whitespace, a period, a comma or the beginning or end of the line. You can assume that the input consists entirely of letters, whitespaces, commas and periods....
Ask the user for a filename. In binary format, read all the integers in that file....
Ask the user for a filename. In binary format, read all the integers in that file. Show the number of integers you read in, along with the maximum and minimum integer found. Language is Java. /////////////input///////// n1.dat ////////// output////////// Enter a filename\n Found 50 integers.\n Max: 9944\n Min: 74\n
Write a program that prompts user to enter integers one at a time and then calculates...
Write a program that prompts user to enter integers one at a time and then calculates and displays the average of numbers entered. Use a while loop and tell user that they can enter a non-zero number to continue or zero to terminate the loop. (Switch statement) Write a program that prompts user to enter two numbers x and y, and then prompts a short menu with following 4 arithmetic operations: Chose 1 for addition Chose 2 for subtraction Chose...
Write a batch program that takes and echoes input data one character at a time until...
Write a batch program that takes and echoes input data one character at a time until EOF is encountered and then prints a summary such as The 14 lines of text processed contained 20 capital letters, 607 lowercase letters, and 32 punctuation marks. Program: C
Write a program that will read user input, and do the following: 1. The user can...
Write a program that will read user input, and do the following: 1. The user can input letters [A-Z] as much as he wants (ignore case). 2. If the user input other than letters or two characters, stop the input process and start to print unduplicated sorted pairs such as the below examples: User input: A a e b d d D E a B 1 Output: AB AD AE BD BE DE User Input: a q w e dd...
Write a program, ArrayRange, that asks the user to input integers and that displays the difference...
Write a program, ArrayRange, that asks the user to input integers and that displays the difference between the largest and the smallest. You should ask the user the number of integers s/he would like to enter (this will allow you to set the length of the array). Allow the user to input all the numbers and then store them in the array. Search the array for the largest number, then search for the smallest, and finally compute the calculation. Display...
How do you validate in pseudocode a "REPEAT" "UNTIL" loop? For example if a user inputs...
How do you validate in pseudocode a "REPEAT" "UNTIL" loop? For example if a user inputs invalid data there should be an error message that reprompts for correct data. To show this can you write Pseudo Code for the following problem? Create an application that can determine the yearly bonus for all company employees. Not all employees are eligible for a yearly bonus. Only employees that have been with the company longer than 2 years and must have been given...
Write a java program that will ask the user to enter integers (use loops) until -100...
Write a java program that will ask the user to enter integers (use loops) until -100 is entered. The program will find and display the greatest, the smallest, the sum and the average of the entered numbers. also write a separate driver class which will be used to run and display the greatest, the smallest, the sum and the average of the entered numbers. Thanks!!
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT