Question

Suppose we have a list x = [43,34,22,32,62,12]. Write a Python program to figure out the...

Suppose we have a list x = [43,34,22,32,62,12]. Write a Python program to figure out the smallest number in the list without using the min() function.

Hint: similar to page 8 on the slide. You can use an arbitrary large number as the temporary smallest number to start the program. Such as temp_smallest = 100.

Homework Answers

Answer #1

x = [43,34,22,32,62,12]

#considering a large number to be the minimum
min_term = 999999

#iterating to each element of the list
for i in x:
#checking if the element is smaller than the min_term
if i < min_term:
#if true, then our new minimum value is the current element
min_term = i

print("Minimum in the list is: ", min_term)

IF THERE IS ANYTHING THAT YOU DO NOT UNDERSTAND, OR NEED MORE HELP THEN PLEASE MENTION IT IN THE COMMENTS SECTION.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a python program that reads a word list and prints out all the anagrams in...
Write a python program that reads a word list and prints out all the anagrams in the word list. In earlier exercises you saw how to read a word list. Also, in earlier examples we saw how the sorted characters of a word are a useful canonical representation of an anagram (Hint: Therefore, useful as a key).
Use python x is a list of strings. For example, x = [’python is cool’, ’pythom...
Use python x is a list of strings. For example, x = [’python is cool’, ’pythom is a large heavy-bodied snake’, ’The python course is worse taking’] In the example, there is totally 1 occurrence of the word ’python’ (case sensitive) in the strings whose length are more than 20 in the list x. In order to count the number of occurrences of a certain word str in the strings which are long enough, use filter and reduce and write...
Python: Given a list x = [2,3,5,6,7,8,9], write a python program that find those numbers which...
Python: Given a list x = [2,3,5,6,7,8,9], write a python program that find those numbers which are divisible by 3. Arrange these numbers in a list called “result”.
Write a Python program prints out the unique elements of a list lst in a sorted...
Write a Python program prints out the unique elements of a list lst in a sorted manner (i.e it removes duplicates from the list). For example, if list is [10,20,30,20,10,50,60,40,80,50,40], the output should be [10, 20, 30, 40, 50, 60, 80].?
Write a Python program to cut out and display just the Preamble (We the People…). we...
Write a Python program to cut out and display just the Preamble (We the People…). we are trying to pull that line from a text file
PYTHON- write a program that accepts a param (num) that will determine how many numbers will...
PYTHON- write a program that accepts a param (num) that will determine how many numbers will be in the output. every number after the first is the product of the prev 2 numbers, we will always start with [5,2] . return output (list) example. the user will insert 6 as the num. we start with [5,2] and the output will be [5,2,10,20,200,4000]
In Python: Problem 4. Write a program [call it minmax.py] that accepts three integers in the...
In Python: Problem 4. Write a program [call it minmax.py] that accepts three integers in the range [0-100] as input from the user. Your program should then determine and print the smallest and largest integers in the values entered by the user using comparison operators *not* using predefined min or max Python functions. For instance: If the user input is: 36 5 99 your program should give as output: min = 5 max = 99 If the user input is:...
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
Write a python program that prompts the user for a web address (full url, html page)...
Write a python program that prompts the user for a web address (full url, html page) and then uses the BeautifulSoup and urllib to read its data. You can use the any html page you'd like: The program should output the following: The page title (hint: read the content from the metatag "title") The total number of words on the page The total number of unique words on the page The total number of each heading used on the page...
The last thing we will learn about in python is functions. Functions are a great way...
The last thing we will learn about in python is functions. Functions are a great way to organize your program - we use them to write code that is executed only under certain circumstances - for instance when you're using Amazon, any of the following are likely functions within their program: - Add item to cart, determine arrival date,  create a new address, compute taxes, compute shipping charges, charge credit card Because you can write a task-specific function once, and ensure...