answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
kow
25 days ago
13

How to write a program that prompts the user to input two POSITIVE numbers — a dividend (numerator) and a divisor (denominator).

Your program should then divide the numerator by the denominator, and display the quotient followed by the remainder in python.
Computers and Technology
1 answer:
Rzqust [894]25 days ago
3 0

Answer:

num1 = int(input("Numerator: "))

num2 = int(input("Denominator: "))

if num1 < 1 or num2<1:

     print("Input must be greater than 1")

else:

     print("Quotient: "+str(num1//num2))

     print("Remainder: "+str(num1%num2))

Explanation

The next two lines prompt the user for two numbers

num1 = int(input("Numerator: "))

num2 = int(input("Denominator: "))

The next if statement checks whether either or both inputs are not positive

if num1 < 1 or num2<1:

     print("Input must be greater than 1")-> If true, this print statement will run

If the conditions are not met, the program prints the quotient and remainder

else:

     print("Quotient: "+str(num1//num2))

     print("Remainder: "+str(num1%num2))

You might be interested in
Q2 - Square Everything (0.25 points) Write a function called square_all that takes an input called collection that you assume to
zubka84 [945]
Refer to the explanation Define the function square_all() that receives a list of integers. This function should return a new list containing the square values of all integers found within the provided list. def square_all(num_list): #Initiate an empty list to store results. sq_list = [] #Iterate through the length of the list. for index in range(0, len(num_list)): #Calculate the square of the current value and add it to the result list sq_list. sq_list.append(num_list[index] * num_list[index]) #Return the squared values of all integers in num_list. return sq_list #Declare and initialize a list of integers. intList = [2, 4] #Invoke the square_all() function and pass the above list as an argument. Show the returned list. print(square_all(intList))
4 0
20 days ago
In this code, identify the repeated pattern and replace it with a function called month_days, that receives the name of the mont
8_murik_8 [892]

Answer:

Below is the month_days function:

def month_days(month, days):

 print (month +" has " + str(days) + " days.")

You can invoke this function with arguments like:

month_days ("June", 30)

month_days("July", 31)

The function can also be restructured as follows:

def month_days(month, days):

 return (month +" has " + str(days) + " days.")

To view the output, call the function along with print like this:

print(month_days ("June", 30))

print(month_days("July", 31))

Explanation:

The defined month_days function takes two parameters: the month name and the number of days in that month. It has a return statement return (month +" has " + str(days) + " days.") which combines the month name held in the variable month with the word "has" and then the number of days stored in days followed by the term days.

For instance, if "June" is passed in as month and 30 as days, the output will be:

June has 30 days.

This program can also be constructed using an f-string for better formatting in the month_days function:

def month_days(month, days):

   output = f"{month} has {days} days."

   return (output)

To see the output, invoke the function with print:

print (month_days("June", 30))

print (month_days("July", 31))

The f-string starts with 'f' and includes the parameters month and days within curly braces. The variables month and days are substituted with their respective values when the function is called.

Screenshot of the program and its output is attached.

6 0
1 month ago
Write a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins with a
8_murik_8 [892]

Answer:

Below is the JAVA program:

import java.util.Scanner;   //to take input from user

public class Main {  //name of the class

  public static void main(String[] args) {  //beginning of main method

      Scanner input = new Scanner(System.in);  //creates Scanner instance

      int integer = input.nextInt();  //defines and collects an integer for the number of words

      String stringArray[] = new String[integer]; //initializes an array to hold strings

      for (int i = 0; i < integer; i++) {  //iterates through the array

          stringArray[i] = input.next();         }  //collects strings

      int frequency[] = new int[integer];  //creates an array for holding frequencies

      int count;         //initializes variable to calculate frequency of each word

      for (int i = 0; i < frequency.length; i++) {  //iterates through frequency array

          count = 0;  //sets count to zero

          for (int j = 0; j < frequency.length; j++) {  //iterates through array

              if (stringArray[i].equals(stringArray[j])) {  //checks if element at ith index matches jth index

                  count++;                 }            }  //increments count

          frequency[i] = count;      }  //stores count in the frequency array

      for (int i = 0; i < stringArray.length; i++) {  //iterates through the string array

          System.out.println(stringArray[i] + " " + frequency[i]);         }    }    } //displays each word and its frequency

Explanation:

To illustrate the program, consider:

let integer = 3

for (int i = 0; i < integer; i++) is used to input strings into stringArray.

On the first pass:

i = 0

0<3

stringArray[i] = input.next(); takes a word and saves it to the ith index of stringArray. For example, if the user types "hey", it will be in stringArray[0].

Then, i increments to i = 1

On the second pass:

i = 1

1<3

stringArray[i] = input.next(); takes another word and assigns it to stringArray[1]. If the user enters "hi", then hi will be in stringArray[1]

Next, i becomes i = 2

On the third pass:

i = 2

2<3

stringArray[i] = input.next(); captures a word and places it in stringArray[2]. If the user types "hi", it goes to stringArray[2]

Then, i increments to i = 3

The loop terminates since i<integers is false.

The next outer loop for (int i = 0; i < frequency.length; i++) and inner loop for (int j = 0; j < frequency.length; will check each word and if (stringArray[i].equals(stringArray[j])) identifies any duplicates. Words that repeat will have their count incremented and the frequency array will record these values. For example, hey appears once while hi shows up twice, thus resulting in the final outputs:

hey 1

hi 2

hi 2

The visual representation of the program and its outcome based on the example provided is attached.

4 0
1 month ago
Which of the following best describes the protocols used on the Internet?
amid [805]
Typical Internet protocols encompass TCP/IP (Transmission Control Protocol/Internet Protocol), UDP/IP (User Datagram Protocol/Internet Protocol), HTTP (HyperText Transfer Protocol), and FTP (File Transfer Protocol).
8 0
20 days ago
In mathematics, the factorial of a positive integer n, denoted as n! , is the product of all positive integers less than or equa
oksian1 [804]
public static int factorial(int n) { if (n >= 1 && n <=12) { if (n == 1) return 1; else return n * factorial(n - 1); } else return -1; } Explanation: The factorial method takes a single integer n as input. It checks if n is within the range of 1 to 12. If it is, it further checks if n equals 1. If it is indeed 1, it returns 1 as the factorial. Otherwise, it recursively calls itself with n decreased by 1, multiplying the result by n. If n is outside this range, the method returns -1 indicating the input is invalid.
6 0
11 days ago
Read 2 more answers
Other questions:
  • 3.14 LAB: Input and formatted output: Caffeine levels A half-life is the amount of time it takes for a substance or entity to fa
    9·1 answer
  • How to code 2.9.5: Four colored triangles {Code HS}
    10·1 answer
  • Why computer is known as versatile and diligent device ?explain​
    14·1 answer
  • Users report that the network access is slow. After questioning the employees, the network administrator learned that one employ
    7·1 answer
  • Recall that with the CSMA/CD protocol, the adapter waits K. 512 bit times after a collision, where K is drawn randomly. a. For f
    5·1 answer
  • Create a different version of the program that: Takes a 3-digit number and generates a 6-digit number with the 3-digit number re
    14·1 answer
  • Describe a situation involving making a copy of a computer program or an entertainment file of some sort for which you think it
    7·1 answer
  • A wireless network does not benefit like a wired network does, when it comes to collision reduction. Which device reduces collis
    6·1 answer
  • The position of a runner in a race is a type of analog data. The runner’s position is tracked using sensors. Which of the follow
    8·1 answer
  • A router has a valid operating system and a configuration file stored in nvram. the configuration file contains an enable secret
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!