1answer.
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
tatyana61 [14]
3 years ago
12

Write a function called largest3 which takes 3 numbers as parameters and returns the largest of the 3. Write a program which tak

es 3 numbers as input from the user and then calls the function with those 3 numbers as parameters. The function will reutrn the largest number. Your program should then output this returned largest number. The input and output parts should be outside the function. The functions should only take 3 numbers as parameters and return the largest one.
Engineering
1 answer:
tamaranim1 [39]3 years ago
6 0

Answer:

The solution code is written in Python.

  1. def largest3(num1, num2, num3):
  2.    largest = num1
  3.    if(largest < num2):
  4.        largest = num2
  5.    
  6.    if(largest < num3):
  7.        largest = num3
  8.    
  9.    return largest
  10. first_num = int(input("Enter first number: "))
  11. second_num = int(input("Enter second number: "))
  12. third_num = int(input("Enter third number: "))
  13. largest_number = largest3(first_num, second_num, third_num)
  14. print("The largest number is " + str(largest_number))

Explanation:

<u>Create function largest3</u>

  • Firstly, we can create a function <em>largest3 </em>which take 3 numbers (<em>num1, num2, num3</em>) as input. (Line 1).
  • Please note Python uses keyword <em>def </em>to denote a function. The code from Line 2 - 10 are function body of <em>largest3</em>.
  • Within the function body, create a variable,<em> largest</em>, to store the largest number. In the first beginning, just tentatively assign<em> num1 </em>to<em> largest</em>. (Line 2)
  • Next, proceed to check if the current "<em>largest</em>" value smaller than the<em> num2 </em>(Line 4). If so, replace the original value of largest variable with <em>num2</em> (Line 5).
  • Repeat the similar comparison procedure to<em> </em><em>num3</em> (Line 7-8)
  • At the end, return the final value of "<em>largest</em>" as output

<u>Get User Input</u>

  • Prompt use input for three numbers (Line 13 -15) using Python built-in <em>input</em> function.
  • Please note the input parts of codes is done outside of the function <em>largest3</em>.

<u>Call function to get largest number and display</u>

  • We can simply call the function<em> largest </em>by writing the function name <em>largest</em> and passing the three user input into the parenthesis as arguments. (Line 17)
  • The function <em>largest </em>will operate on the three arguments and return the output to the variable <em>largest_number</em>.
  • Lastly, print the output using Python built-in <em>print</em> function. (Line 18)
  • Please note the output parts of codes is also done outside of the function<em> largest3</em>.
You might be interested in
java Write a program that simulates tossing a coin. Prompt the user for how many times to toss the coin. Code a method with no p
max2010maxim [7]

Answer:

The solution code is written in Java.

  1. public class Main {
  2.    public static void main(String[] args) {
  3.        Scanner inNum = new Scanner(System.in);
  4.        System.out.print("Enter number of toss: ");
  5.        int num = inNum.nextInt();
  6.        for(int i=0; i < num; i++){
  7.            System.out.println(toss());
  8.        }
  9.    }
  10.    public static String toss(){
  11.        String option[] = {"heads", "tails"};
  12.        Random rand = new Random();
  13.        return option[rand.nextInt(2)];
  14.    }
  15. }

Explanation:

Firstly, we create a function <em>toss()</em> with no parameter but will return a string (Line 14). Within the function body, create an option array with two elements, "heads" and "tails" (Line 15). Next create a Random object (Line 16) and use <em>nextInt()</em> method to get random value either 0 or 1. Please note we need to pass the value of 2 into <em>nextInx() </em>method to ensure the random value generated is either 0 or 1.  We use this generate random value as an index of <em>option </em>array and return either "heads" or "tails" as output (Line 17).

In the main program, we create Scanner object and use it to prompt user to input an number for how many times to toss the coin (Line 6 - 7). Next, we use the input num to control how many times a for loop should run (Line 9). In each round of the loop, call the function <em>toss() </em>and print the output to terminal (Line 10).  

4 0
4 years ago
Read 2 more answers
A heat recovery device involves transferring energy from the hot flue gases passing through an annular region to pressurized wat
Elina [12.6K]

Answer:

See explaination

Explanation:

Please kindly check attachment for the step by step solution of the given problem.

4 0
3 years ago
Solid Isomorphous alloys strength
Sphinxa [80]

Answer:

Explanation:

ℎ

3 0
3 years ago
When an electron in a valence band is raised to a conduction band by sufficient light energy, semiconductors start conducting __
garri49 [273]

Answer:

This band gap also allows semiconductors to convert light into electricity in photovoltaic cells and to emit light as LEDs when made into certain types of diodes. Both these processes rely on the energy absorbed or released by electrons moving between the conduction and valence bands.

Explanation:

On the internet

4 0
3 years ago
WHAT IS THIS PLSSSSSS HELP
alekssr [168]

Answer:

It looks like... A machine that reads electric pulse and surge... Not sure though.

Explanation:

8 0
3 years ago
Other questions:
  • True or false? Engineering degree programs and engineering technology degree programs have a different requirements
    9·1 answer
  • Please what is the name of this tool​
    9·2 answers
  • Extra Credit: The Linc (parking lot and stadium)In celebration of the upcoming Super Bowl, for a maximum 10 points of extra cred
    7·1 answer
  • Write an application named EnterUppercaseLetters that asks the user to type an uppercase letter from the keyboard. If the charac
    8·1 answer
  • Which of the following refers to software designed to alter system files and utilities on a victim’s system with the intention o
    15·1 answer
  • which systems engineering support discipline has the goal to ensure that support considerations are an integral part of the syst
    14·1 answer
  • I NEED HELP ASAP WILL AWARD BRAINLIEST
    8·2 answers
  • B) Calculate the FS against uplift and calculate effoctive stress at the base level for water
    11·1 answer
  • What Number Am I?
    13·1 answer
  • People learn best in different ways. By combining all the group presentations, your class will explain how they see the optical
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!