Question

In: Computer Science

Create a python program that will: prompt a user for a command Command get_data Level 1:...

Create a python program that will:

  • prompt a user for a command

  • Command

    • get_data

  • Level 1: Take one of the commands

    • my_max

    • my_min

    • my_range

    • my_sum

    • mean

    • median

    • mode
    • fib
    • factorize
    • prime

Requirements:

  • Your commands should be case-insensitive

  • You should use python lists to store data

  • You should NOT use built-in python math functions, or math libraries to compute these values

Tips:

  • Write one function that will convert a string with comma-separated numbers into a python list with the numbers. You can use this in multiple other functions.

  • Don't name any of your functions "min", "max", or "range" or "sum". These are built-in functions.




Details

Load command details

  • Get_data: prompts users for a list of numbers, separated by commas

    • (please also print the list, for testing)

Level 1 details (these functions work with the loaded data list)

  • my_max

  • my_min

  • my_range: Computes the range (difference of greatest value and least value)

  • my_sum

  • mean: Computes and prints the arithmetic mean (average)

Level 2

  • median: show the median (middle value, or average of two middle values)

  • mode: show the mode, or modes

Level 3 details (these functions should use the first number in the data list)

  • prime: determine if a number is prime

  • factorize: get the prime factors of a number

  • fib: get the nth number in the fibonacci sequence

Here is my code so far:

#hehe my sum and stuff
f = open("input.txt",'r')
def input(prompt=''):
print(prompt, end='')
return f.readline().strip()   

#get data
def get_data():
pass

line = input().strip().split(',')
  
nums=[]
for n in line:
nums.append(float(n))

  
return nums
  
#get sum
def my_sum(data):
  
s=0
for n in data:
s += n
return s
  
pass

#get max
def my_max(data):
  
m=0
for n in data:
m >= n
return m

pass

#get min
def my_min(data):
  
i=0
for n in data:
i < n
return i

pass

#get range
def my_range(data):
r=0
for n in data:
m - i
return r

pass

#get mean
def mean(data):
e=0
for n in data:
????????

#get median
def median(data):
d=0
for n in data:
??????
  
#get mode
def mode(data):
o=0
for n in data:
???
  
#get prime
def prime(data):
p=0
for n in data:
???

#get factorization
def factorization(data):
f=0
for n in data:
????
  
#get fib
def fib(data):
b=0
for n in data:
??
#run it
def run_cli():
  
while(1):
cmd = input()
  
if cmd=='exit':
break
  
elif cmd=='get_data':
data = get_data()
print(data)
  
  
elif cmd=='my_sum':
s = my_sum(data)
print(s)
  
elif cmd=='my_max':
m = my_max(data)
print(m)
  
elif cmd=='my_min':
i = my_min(data)
print(i)
  
elif cmd=='my_range':
r = my_range(data)
print(r)
  
elif cmd=='mean':
e = mean(data)
print(e)
  
elif cmd=='median':
d = median(data)
print(d)
  
elif cmd=='mode':
o = mode(data)
print(o)
  
elif cmd=='prime':
p = prime(data)
print(p)
  
elif cmd=='factorization':
f = factorization(data)
print(f)
  
elif cmd=='fib':
b = fib(data)
print(b)
  
pass

#ha ahsbas
def main():
run_cli()
  
main()

Solutions

Expert Solution

Heres the missing functions, please do as needed and if you need any further help you can always reach out to me in comments

f = open("input.txt",'r')
def input(prompt=''):
    print(prompt, end='')
    return f.readline().strip()   

#get data
def get_data():
    pass

    line = input().strip().split(',')
  
    nums=[]
    for n in line:
        nums.append(float(n))

  
    return nums
  
#get sum
def my_sum(data):
  
    s=0
    for n in data:
        s += n
        return s
        
        pass

#get max
def my_max(data):
  
    m=0
    for n in data:
        m >= n
        return m

        pass

#get min
def my_min(data):
  
    i=0
    for n in data:
        i < n
        return i

        pass

#get range
def my_range(data):
    r=0
    for n in data:
        m - i
        return r

        pass

#get mean
def mean(data):
    e=0
    for n in data:
    #????????
        e+=n
    return e/len(data)

#get median
def median(data):
    data.sort()
    return data[len(data)/2]
  
#get mode
def mode(data):
    n = len(data) 
  
    data = Counter(data) 
    get_mode = dict(data) 
    mode = [k for k, v in get_mode.items() if v == max(list(data.values()))] 
    
    if len(mode) == n: 
        get_mode = "No mode found"
    else: 
        get_mode = "Mode is / are: " + ', '.join(map(str, mode)) 
        
    print(get_mode) 
  
  #check_prime
  def check_prime(num):
    if num > 1:  
        for i in range(2,num):  
            if (num % i) == 0:  
                return False
        else:  
            return True
            
    else:
         return True 
#get prime
def prime(data):
    for n in data:
    if(check_prime(n)==True) print(n)

#get factorization
def factorization(data):
    for i in range(1:data+1):
        if(data%i==0) print(i)
  
#get fib
def fib(data):
    if(data == 0):
        return 0
    elif(data == 1):
        return 1
    else:
        return (Fibonacci_series(data - 2) + Fibonacci_series(data - 1))
#run it
def run_cli():
  
    while(1):
        cmd = input()
        
        if cmd=='exit':
            break
    
    elif cmd=='get_data':
        data = get_data()
        print(data)
    
  
    eliif cmd=='my_sum':
        s = my_sum(data)
        prnt(s)
  
    elif cmd=='my_max':
        m = my_max(data)
        print(m)
    
    elif cmd=='my_min':
        i = my_min(data)
        print(i)
    
    elif cmd=='my_range':
        r = my_range(data)
        print(r)
        
    elif cmd=='mean':
        e = mean(data)
        print(e)
    
    elif cmd=='median':
        d = median(data)
        print(d)
    
    elif cmd=='mode':
        o = mode(data)
        print(o)
    
    elif cmd=='prime':
        p = prime(data)
        print(p)
    
    elif cmd=='factorization':
        f = factorization(data)
        print(f)
    
    elif cmd=='fib':
        b = fib(data)
        print(b)
        
    pass

#ha ahsbas
def main():
    run_cli()
  
main()

Related Solutions

In Python, your program will read in a number (no need to prompt the user), and...
In Python, your program will read in a number (no need to prompt the user), and then reads in that number of lines from the terminal. Then the program should print an array of strings formatted in a nice regular box. So if the user inputs this: 5 Grim visaged war has smooth’d his wrinkled front And now, instead of mounting barded steeds To fright the souls of fearful adversaries He capers nimbly in a lady’s chamber To the lascivious...
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
Create in java a program that will prompt the user to enter a weight for a...
Create in java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates infusion rates based on weight of patient in an interactive GUI application, label it HEPCALC. The patients’ weight will be the only entry from the user. To calculate the infusion rate you will multiply 12 times the weight divided by 50 for a total number. The end result will need to round up or down the whole number....
5) Create the following in a Java program Create a scanner Prompt the user to enter...
5) Create the following in a Java program Create a scanner Prompt the user to enter the name where the box of mail is shipping from and create the variable and relate to scanner Prompt the user to enter the name of destination where the box of mail will be shipped and create the variable and relate to scanner Prompt the user to enter the weight of the package and create variable to relate to scanner Calculate cost of shipping...
create a program that will verify a user's login credentials. The program should prompt the user...
create a program that will verify a user's login credentials. The program should prompt the user to enter his/her username and password at the keyboard. Then it should read the data from a data file named "login.txt". The file "login.txt" will contain a list of 3 valid usernames and passwords to verify the login information supplied by a user.  If the username and password entered by the user matches one of the sets read from the file, the program should print...
8.30 LAB*: Program: Authoring assistant. PYTHON PLEASE!! (1) Prompt the user to enter a string of...
8.30 LAB*: Program: Authoring assistant. PYTHON PLEASE!! (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: we'll continue our quest in space. there will be more shuttle flights and more shuttle crews and, yes; more volunteers, more civilians, more teachers in space. nothing ends here; our hopes and our journeys continue! You entered: we'll continue our quest in space. there will be...
Python Add a command to this chapter’s case study program that allows the user to view...
Python Add a command to this chapter’s case study program that allows the user to view the contents of a file in the current working directory. When the command is selected, the program should display a list of filenames and a prompt for the name of the file to be viewed. Be sure to include error recovery in the program. If the user enters a filename that does not exist they should be prompted to enter a filename that does...
Create a Python program that: Allows the user to enter a phrase or sentence. The program...
Create a Python program that: Allows the user to enter a phrase or sentence. The program should then take the phrase or sentence entered Separate out the individual words entered Each individual word should then be added to a list After all of the words have been place in a list Sort the contents of the list Display the contents of the sorted list with each individual word displayed on a separate line Display a message to the user indicating...
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Create a program that will prompt for user information for a Web site. Use a structure...
Create a program that will prompt for user information for a Web site. Use a structure to store the data. The structure will need to include the following items: First Name - string Last Name - string Full Name - string Birth Date   - int (assume format yyyymmdd) IsLeasingAutomobile - bool yearlySalary - float Create a single structure from the items listed above. Prompt for all items except "Full Name" and load the input directly into a variable based on...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT