Question

In: Computer Science

Write a decision-making program with command-line interface to implement a housing-score calculator (inspired by the 2020...

Write a decision-making program with command-line interface to implement a housing-score calculator (inspired by the 2020 Nifty Decision Makers by Evan Peck)

Your program will consist of two functions:

  • main()
    • Asks the user 5 questions and stores the answers: year (int), age (int), probation (string), full-time (int), gpa (float) (see sample run below)
    • Calls computeScore(answers), where answers is a list containing the variables in which the answers are stored in the order in which they are received (python lists may contain variables of different type)
    • Prints the value returned by computeScore
  • computeScore(answers)
    • Computes the housing score based on the values in answers as follows:
      • Current Freshman: 1 point
      • Current Sophomore: 2 points
      • Current Junior: 3 points
      • Current Senior: 4 points
      • 23+ Years of Age: 1 point
      • Full-Time: 1 point
      • Academic Probation: -1 point
      • 3.5+ GPA: 1 point
    • Returns the housing score

A sample run of the program:

  -----------------------------------
  HOUSING SCORE CALCULATOR
  -----------------------------------

  QUESTION 1
  What year are you? (1,2,3,4): 4
  QUESTION 2
  How old are you?: 25
  QUESTION 3
  Are you currently on probation? (Yes or No): No
  QUESTION 4
  Are you Part-time or Full-time? (0 or 1): 1
  QUESTION 5
  What is your GPA?: 3.9

  -----------------------------------
  Your housing score is:  7
  -----------------------------------
  

And another sample run of the program:

  -----------------------------------
  HOUSING SCORE CALCULATOR
  -----------------------------------

  QUESTION 1
  What year are you? (1,2,3,4): 2
  QUESTION 2
  How old are you?: 19
  QUESTION 3
  Are you currently on probation? (Yes or No): Yes
  QUESTION 4
  Are you Part-time or Full-time? (0 or 1): 0
  QUESTION 5
  What is your GPA?: 2.7

  -----------------------------------
  Your housing score is:  1
  -----------------------------------
  

The grading script runs the whole program as well as each function separately ('unit tests') to determine correctness. As such, the function names must match exactly as indicated above (else, the scripts cannot find them).

Your program may assume that the input (from the user and to the functions) is always in the expected format.

Solutions

Expert Solution

# this list stores the answers to all 5 questions
answers=[]

def computeScore(answers):
    score=0
    
    score+=answers[0]
    
    if answers[1]>23:
        score+=1
    
    if answers[2]=="Yes":
        score-=1
    
    score+=answers[3]
    
    if answers[4]>3.5:
        score+=1
    
    return score
    
# all thee questions from 1 to 5 are asked
# all the answers are appended to the list

print("HOUSING SCORE CALCULATOR\n")

print("QUESTION 1")
answers.append(int(input("What year are you? (1,2,3,4): ")))

print("\nQUESTION 2")
answers.append(int(input("How old are you?: ")))

print("\nQUESTION 3")
answers.append(input("Are you currently on probation? (Yes or No): "))

print("\nQUESTION 4")
answers.append(int(input(" Are you Part-time or Full-time? (0 or 1): ")))

print("\nQUESTION 5")
answers.append(float(input("What is your GPA?: ")))

# computeScore function calculates the score on the basis of answers to the 5 questions
score=computeScore(answers)

# print the score
print("Your housing score is:  ",score)

PLEASE LIKE THE SOLUTION :))

IF YOU HAVE ANY DOUBTS PLEASE MENTION IN THE COMMENT


Related Solutions

Write a script that represents a simple command line calculator. It will accept two numbers from...
Write a script that represents a simple command line calculator. It will accept two numbers from command line, and then display sum, difference and product of these two numbers. Provide script code and screenshot of output. Using Linux Ubuntu bash
Introduction Write in C++ at the Linux command line a program that is the same as...
Introduction Write in C++ at the Linux command line a program that is the same as the previous collection app project but now uses a class to store the items and also can save the items to a file that can be read back into the array by the user when the program is re-started. You can use your project 1 submission as a starting point or you can do something new as long as it meets the listed requirements....
Write a program that takes two command line arguments at the time the program is executed....
Write a program that takes two command line arguments at the time the program is executed. You may assume the user enters only decimal numeric characters. The input must be fully qualified, and the user should be notified of any value out of range for a 23-bit unsigned integer. The first argument is to be considered a data field. This data field is to be is operated upon by a mask defined by the second argument. The program should display...
write code in java and comment. thanks. the program is about interface . Implement the basics...
write code in java and comment. thanks. the program is about interface . Implement the basics of Fitness and types of Fitness: Aerobic. Implement specific Fitness types such as Swimming, Cycling, Fitness Task: public interface Fitness (10pts) This will be used as a starting point for deriving any specific Fitness type. Every fitness exercise type has one or more muscle group it affects. Therefor a Fitness has the following abstarct method (Note that all methods in an interface are abstract...
Program 3: Command Line Calculator Topics: Functions or methods, global variables Overview You will build a...
Program 3: Command Line Calculator Topics: Functions or methods, global variables Overview You will build a simple command line calculator. It supports addition (add), subtraction (sub), multiplication (mul), division (div), and calculation of the absolute value (abs). You will use functions to support each type of calculation. You can assume that the numbers are float data types. Software Specifications The user interacts with program by entering a command, followed by some parameters at the command prompt “>”. For example, if...
1. Specification Write a C program to implement a simple calculator that accepts input in the...
1. Specification Write a C program to implement a simple calculator that accepts input in the following format and displays the result of the computation: calc [operand_1] [operator] [operand_2] The operands operand_1 and operand_2 are non-negative integers. The operator is one of the following: addition (+), subtraction (-), multiplication (x), division (/) and modulo (%). Note: For the multiplication operator, use letter ‘x’. If you use the asterisk ‘*’, your program will not work properly 2. Implementation • The program...
write a program ordered.java Order check Write a program Ordered.java that takes four int command-line arguments...
write a program ordered.java Order check Write a program Ordered.java that takes four int command-line arguments w, x, y, and z. Define a boolean variable whose value is true if the four values are either in strictly ascending order (w < x < y < z) or strictly descending order (w > x > y > z), and false otherwise. Then, display the boolean variable value. NOTE 1: Do not use if statements on this program. NOTE 2: Assume that...
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For...
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For example, java Adder 3 2.5 -4.1 should print The sum is 1.4
Write a program that takes an integer N from the command line and uses StdRandom.uniform() to...
Write a program that takes an integer N from the command line and uses StdRandom.uniform() to generate a random sequence of integers be- tween 0 and N – 1. Run experiments to validate the hypothesis that the number of integers generated before the first repeated value is found is ~√?N/2.
Write a C program that accepts a port number as a command line argument, and starts...
Write a C program that accepts a port number as a command line argument, and starts an HTTP server. This server should constantly accept() connections, read requests of the form: GET /path HTTP/1.1\r\n\r\n read the file indicated by /path, and send it over the "connect" file descriptor returned by the call to accept().
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT