Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a Python program that inputs an integer base and a list alist of integers. The list should be set up using assignment in the

Write a Python program that inputs an integer base and a list alist of integers. The list should be set up using assignment in the program. The goal of the program is to print the largest value in alist that is smaller than base. The program also needs to print the position of this value in alist (see the example below). Note, do not sort this list. You should be able to solve this problem going through the list only once (or twice). Do not use built-in functions other than those allowed in the course (e.g. len, input, int, range, list, print). If there is no value smaller than the base then the program will print an appropriate message as indicated below. Remember that the TAs will potentially change the list (and its size) in order to test your program so your program must be general for different base numbers, list values and list sizes. You can assume that the integers in alist are unique.

For example

If [52, 4, -1, 17, 81, -2, 75, 24] is assigned to alist and base is 14, then the output will be "4 at position 1 is the largest value in the list that is smaller than 14"

If instead the base was -10, then the output will be "There are no numbers smaller than -10 in this list

Can only use the built in functions on the picture provided.

image text in transcribed

Python Reminders a=b assignment ( a is assigned the value of b ) Arithmetic operations: +,,,/,// the last one is integer division a%b gives the remainder of a divided by b. Conditional Operators equalgreaterthanlessthan=>=lessthanorequal

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 Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

1. Where will you recommend that she hold the focus group?

Answered: 1 week ago

Question

3. What might you have done differently

Answered: 1 week ago