Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help to fix some python code This what the python program should be able to do: i think i got everything, except for

I need help to fix some python code This what the python program should be able to do: i think i got everything, except for "Display the list in sorted order (largest to smallest) by calling a function sorted that you code Use the sorted() function in the template" 

can anyone modify the code so it can display the list in sorted order (largest to smallest)

Populate an array of size n = 20 with random integers in the range 10 ---- 50 inclusive but do NOT include any duplicates. The list of n integers should include only unique integers in the range 10 25

Strategy

Generate a random integer (1)

If it NOT in the list add to the list

Else return to (1) that is generate another random integer

USE the fill() function in the template below

Display the list using the display() function

Display the list in sorted order (largest to smallest) by calling a function sorted that you code Use the sorted() function in the template

Display the minimum integer in the list using your function min()

Display the maximum integer in the list using your function max()

Display the number of integers that are evenly divisible by 3 (no remainder) using your function div3() . Integers in the array that are evenly divisible be 3 are { 12, 15, 18, 21, 24}

Please use x mod 3 as in

Select an integer from your list call it x. If x mod 3 == 0 then add 1 to a counter

Use the div3() in the template

Display the number of integers in the list that are multiples of 5 (10, 15, 20,25) by coding a function mult5()

Use the mult5() in the template

Ask the user for an integer and display YES if the integer appears in the list or NO if it is in the list by calling the yesNo() function

  CODE: import random def display(a): print("the list == ", a) # DONE  def sorted (a): # sort the array a from largest to smallest # Consider using the python sort function  return a def fill(a,n): # fill the list a with n random integers in the range 10 --- 25 inclusive BUT NO duplicates THIS code NEEDS to be fixed  ar = 10 br = 50 j = 0 while(len(a)<20): x = random.randint(ar, br) # Return a random integer .  if x not in a: a.append(x) return a def div3 (a): v = 0; for x in a: if(x%3==0): v=v+1 return v def multi5(a): m = 0 for x in a: if(x%5==0): m=m+1 return m def yesNo(a): s = "YES"  n= "NO"  num =int( input("Enter a number:")) if num in a: return s else: return n def max(a): # return the largest value in the list  mx = a[0] # place holder only  for num in a: if(num>mx): mx=num return mx def min(a): # return the smallest value in the list  mn = a[-1] for num in a: if(numreturn mn # ========================================== # NOW we call the functions a = [] n = 20 # array size  array = fill(a,n) display(array) mx = max(array) mn = min(array) d = div3(array) m = multi5(array) print( "Maximum is : ", mx, "Minimum is :", mn) print( "div3 return is : ", d, " multi5 return value is :", m) str = yesNo(array) print(str) 

OUTPUT

the list == [14, 35, 45, 34, 32, 49, 48, 11, 15, 20, 26, 30, 47, 24, 23, 44, 16, 21, 40, 18] Maximum is : 49 Minimum is : 11 div3 return is : 7 multi5 return value is : 6 Enter a number:

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

JDBC Database Programming With J2ee

Authors: Art Taylor

1st Edition

0130453234, 978-0130453235

More Books

Students also viewed these Databases questions

Question

How is slaked lime powder prepared ?

Answered: 1 week ago

Question

Why does electric current flow through acid?

Answered: 1 week ago

Question

What is Taxonomy ?

Answered: 1 week ago

Question

1. In taxonomy which are the factors to be studied ?

Answered: 1 week ago