Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python beginner question, plz don't make the code very complex. Question 1 (15 points] This question will ask you to do an exercise involving lists.

Python beginner question, plz don't make the code very complex.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Question 1 (15 points] This question will ask you to do an exercise involving lists. You are asked to write a function fetch that takes in a list of positive, non-zero integers, and returns the smallest integer not in the list. For example, the smallest positive integer not in the list [1, 5, 2] is 3, so the function should return 3. You must also write a function get input from user that creates a list based on user input, which we will use to create the list for the first function. The two functions should be implemented as follows: Name: fetch Parameters: A list numbers' of positive, non-zero integer values. Return value: The smallest positive integer not in the list. If an empty list is given, return the value 1. Name: get_list_from_input Parameters: No parameters Return value: A list of positive, non-zero integers entered by the user. What it should do: Ask the user to enter a number(s) with the prompt 'Enter number(s): 1 then convert their entered numbers to integer and store them in a list. Keep asking the user to enter numbers until they enter the word 'done', at which point you should return the list of all numbers entered. The user may enter just one number on a line, or they could enter a series of comma-separated numbers, in which case each of the numbers must be added to the list. If the user enters any values less than 1, do not add them to the list. For example, if the user enters "4,5,-2" on one line, 4 and 5 should be added to the list, but -2 should not. You can assume the user will not enter any spaces, and only enter digits from 0-9 without any letters or special characters. # Assignment 1, Question 1 def fetch(numbers): pass # delete this line and add your code here def get_list_from_input(): pass # delete this line and add your code here numbers = get_list_from_input(). print(fetch(numbers)) Examples (as executed in Thonny) EXAMPLE 1: >>> %Run sequence.py Enter number(s): done EXAMPLE 2: >>> %Run sequence.py Enter number(s): 0 Enter number(s): done EXAMPLE 3: >>> %Run sequence.py Enter number(s): 1 Enter number(s): done EXAMPLE 4: >>> %Run sequence.py Enter number(s): 1 Enter number(s): 5 Enter number(s): 2 Enter number(s): done EXAMPLE 5: >>> %Run sequence.py Enter number(s): 1 Enter number(s): 2 Enter number(s): 3 Enter number(s): 4 Enter number(s): done EXAMPLE 6: >>> %Run sequence.py Enter number(s): 1,5,2 Enter number(s): 3,7,6 Enter number(s): 4,8 Enter number (s): done

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions