Question
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.
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=>
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started