Question

Assignment Content PROGRAM DESCRIPTION Make a program that will allow the user to select a choice from the following options:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#PYTHON PROGRAM FOR THE ABOVE GIVEN PROBLEM

#imported math for built-in factorial method requirement

import math

#getCount method printing the count of negative and positive numbers

def getCount():

    countNeg = 0

    countPos = 0

    number = input()

    number = number.lower()

    while number!='x':

        number = int(number)

        if number<0:

            countNeg+=1

        elif number>=0:

            countPos+=1

        number = input()

        number = number.lower()

           

    print("total positive numbers:",countPos)

    print("total negative numbers:",countNeg)

#getSum method to print the sum of the numbers entered

def getSum():

    ans = 0

    inp = input()

    inp = inp.lower()

    while inp != 'x':

        inp = int(inp)

        ans+=inp

        inp = input()

        inp = inp.lower()

    print("sum is:",ans)

#isPrime method to check whether a number is prime or not

def isPrime(n):

    if n==1:

        return False

    if n%2==0:

        return False

    a = int(n**(1/2))+1

    for i in range(3,a,2):

        if n%i==0:

            return False

    return True

def checkNum():

    num = int(input())

    print("is the number prime?:",isPrime(num))

    

#method to get the factorial of the number entered using built-in factorial method

def getFactorial():

    num = int(input())

    print("factorial is:",math.factorial(num))

#main method that contains the driver code

def main():

    while True: #the loop continues until the user presses 'x'

        print("A. GetCount")

        print("B. GetSum")

        print("C. CheckNum")

        print("D. GetFactorial")

        print("X. Exit")

        choice = input()

        choice = choice.lower()

        if choice=='a':

            getCount()

        elif choice=='b':

            getSum()

        elif choice=='c':

            checkNum()

        elif choice=='d':

            getFactorial()

        elif choice=='x':

            break

        else:

            print("You made a wrong choice.")

main()

###############PROGRAM END#####################################

note: The modules are made as per our interpretation of the description of the methods, if the requirements are different, please specify along with the example or test case.

Add a comment
Know the answer?
Add Answer to:
Assignment Content PROGRAM DESCRIPTION Make a program that will allow the user to select a choice...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • USING PYTHON PLEASE Write a program that calculates the factorial value of a number entered by...

    USING PYTHON PLEASE Write a program that calculates the factorial value of a number entered by the user. Remember that x! =x* (x-1)* (x-2)*... *3+ 2* 1. Your program should check the value input by the user to ensure it is valid (i.e., that it is a number > =1). To do this, consider looking at the is digit() function available in Python. If the user enters an incorrect input, your program should continue to ask them to enter a...

  • Assignment Develop a program to analyze one or more numbers entered by a user. The user...

    Assignment Develop a program to analyze one or more numbers entered by a user. The user may enter one or more numbers for analysis. Input should be limited to numbers from 1 through 1000. Determine if a number is a prime number or not. A prime number is one whose only exact divisors are 1 and the number itself (such as 2, 3, 5, 7, etc.). For non-prime numbers, output a list of all divisors of the number. Format your...

  • Write a C – program that calls a user-defined function from within main() that determines the...

    Write a C – program that calls a user-defined function from within main() that determines the minimum value from three positive numbers received from the user. Your function should be called minimum.  You must use a loop to receive the numbers. If the user enters a negative number, you must ask the user to re-enter the number. The function should also print out the positive numbers and the smallest number.

  • // Group Names: // Date: // Program Description: //   Import required packages //--> //   Declare class...

    // Group Names: // Date: // Program Description: //   Import required packages //--> //   Declare class (SwitchDoLab) //--> {    //   Declare the main method    //-->    {        //   Declare Constant integers SUM = 1, FACTORIAL = 2, QUIT = 3.        //-->        //-->        //-->        //   Create an integer variable named choice to store user's option.        //-->        //   Create a Scanner object        //   Create...

  • 1. Write a program to add positive numbers. Ask the user to enter numbers greater than...

    1. Write a program to add positive numbers. Ask the user to enter numbers greater than zero. If a 0, is entered stop requesting numbers and display the total. If a number is entered that is less than 0, display the message ‘Number must be greater than 0’, then ask for another number to be entered. Repeat until a number greater than 0 or 0 is entered. use math lab so I can copy the answers

  • Write a program that calculates the average of a stream of non-negative numbers. The user can...

    Write a program that calculates the average of a stream of non-negative numbers. The user can enter as many non-negative numbers as they want, and they will indicate that they are finished by entering a negative number. For this program, zero counts as a number that goes into the average. Of course, the negative number should not be part of the average (and, for this program, the average of 0 numbers is 0). You must use a method to read...

  • please help Create a program that prompts the user for a sentence and then displays the...

    please help Create a program that prompts the user for a sentence and then displays the hash of the sentence. Refer to the textbook Chapter 5.2 and the Support Video in zyBook section 3.1 for more instruction on hashing. Program Requirements: The program should prompt the user for the "sentence" to be hashed and then compute the hash of the sentence by summing the numeric value of each letter in the sentence (use A=a=1, B=b=2 ... Z=z=26, space=31) and applying...

  • extra credit 1 Write a program that will display the following menu and prompt the user...

    extra credit 1 Write a program that will display the following menu and prompt the user for a selection: A) Add two numbers B) Subtract two numbers C) Multiply two numbers D) Divide two numbers X) Exit program The program should: display a hello message before presenting the menu accept both lower-case and upper-case selections for each of the menu choices display an error message if an invalid selection was entered (e.g. user enters E) prompt user for two numbers...

  • This is Python The program should accept input from the user as either 7-digit phone number...

    This is Python The program should accept input from the user as either 7-digit phone number or 10-digit. If the user enters 7 characters, the program should automatically add "512" to the beginning of the phone number as the default area code. Dash (hyphen) characters do not count in input character count, but must not be random. If the user enters dashes the total character count must not exceed 12. The program should not crash if the user enters invalid...

  • (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the...

    (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the four basic arithmetic operations, i.e., addition, subtraction, multiplication and integer division. A sample partial output of the math quiz program is shown below. The user can select the type of math operations that he/she would like to proceed with. Once a choice (i.e., menu option index) is entered, the program generates a question and asks the user for an answer. A sample partial output...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT