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

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...
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 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.
program c Write a program called filesearch that accepts two command-line arguments: A string A filename...
program c Write a program called filesearch that accepts two command-line arguments: A string A filename If the user did not supply both arguments, the program should display an error message and exit. The program opens the given filename. Each line that contains the given string is displayed. Use the strstr function to search each line for the string. You may assume no line is longer than 255 characters. The matching lines are displayed to standard output (normally the screen).
Python Write a program that takes a text filename as command line argument, and prints number...
Python Write a program that takes a text filename as command line argument, and prints number of times each letter occurred in this file.
Write a Java program which reads a positive integer from the command line, then displays the...
Write a Java program which reads a positive integer from the command line, then displays the sum of all even values up to and including the value provided, followed by the sum of all odd values up to and including the value provided. validate that the command line argument is an integer greater than 0 to validate the type, you can use Integer.parseInt() with a try/catch for NumberFormatException use one or more for loops to perform the even and odd...
**Need to use awk command in putty (should be a ONE LINE COMMAND) Write the command...
**Need to use awk command in putty (should be a ONE LINE COMMAND) Write the command that would find all lines that have an email address and place a label email = before the line in the file longfile output will multiple lines similar to this one : using a good awk command the output would be something like this email = From: "Linder, Jann/WDC" <[email protected]> email = To: Mr Arlington Hewes <[email protected]> email = > From: Mr Arlington Hewes...
The operating system offers a graphical vs command line user interface to interact with an electronic...
The operating system offers a graphical vs command line user interface to interact with an electronic device. Compare the graphical user interface and the command line interface in terms of speed, remote access, resource utilization, multitasking, and control.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT