/*! This file is auto-generated */ .wp-block-button__link{color:#fff;background-color:#32373c;border-radius:9999px;box-shadow:none;text-decoration:none;padding:calc(.667em + 2px) calc(1.333em + 2px);font-size:1.125em}.wp-block-file__button{background:#32373c;color:#fff;text-decoration:none} Problem 15 Write a program that reads in th... [FREE SOLUTION] | 91Ó°ÊÓ

91Ó°ÊÓ

Write a program that reads in three floating-point numbers and prints the largest of the three inputs without using the nax function. For example: Enter a number: 4 Enter a nuirber: 9 Enter a number: \(2.5\) The largest number is 9,0

Short Answer

Expert verified
The largest of the three numbers is printed by comparing each number and updating a variable to keep track of the largest.

Step by step solution

01

Prompt the User for Input

Write code to prompt the user to enter three floating-point numbers. Use the `input()` function to take the input from the user and convert it to a float using the `float()` function. Store these values in three separate variables.
02

Initialize a Variable to Track the Largest Number

Initially, assume the first input is the largest number. Assign the value of the first input to a variable that will hold the largest number.
03

Compare the Second Number

Compare the second number to the current largest number. If the second number is greater, update the variable holding the largest number with the value of the second number.
04

Compare the Third Number

Compare the third number to the current largest number (it may have been updated in Step 3). If the third number is greater, update the variable holding the largest number with the value of the third number.
05

Print the Largest Number

Use the `print()` function to display the largest number to the user. Format the output to convert it into a one decimal point float.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with 91Ó°ÊÓ!

Key Concepts

These are the key concepts you need to understand to accurately answer the question.

Understanding Floating-Point Numbers
Floating-point numbers are a type of numerical data type used in Python to represent real numbers that have decimal points. They are called 'floating-point' because the decimal point can "float"; it can support a large range of values. This is important in programming, especially when dealing with operations that require high precision and when the values are not integers.

In Python, you can create a floating-point number by using the `float()` function. For instance, when you take input from a user that's expected to be a floating-point number, you should convert it to a float using `float(input("Enter a number: "))`.

Floating-point numbers can sometimes behave unpredictably due to the way they are stored in memory. They are stored as approximations, meaning small precision errors can occur. However, they are immensely useful when you need to handle a variety of numbers beyond simple integers.
Using Conditional Statements
Conditional statements are the backbone of decision-making in programming. In Python, they are implemented using `if`, `elif`, and `else` statements. These allow the program to execute different code blocks based on certain conditions.

For instance, to find the largest of three numbers, conditional statements are used to continuously compare one number to another and update the largest number based on these comparisons. The logic might look like this:
  • Start with assuming the first number is the largest.
  • Use an `if` statement to check if the second number is greater than the current ‘largest’. If true, update the largest number.
  • Use another `if` statement to compare the third number with the current largest and update as needed.
These steps ensure that the program checks each condition sequentially, updating the largest number when a bigger number is found.
Taking User Input in Python
User input is a way for programs to interact with the user. In Python, the `input()` function is used to capture input from the user. It's important to note that input received from `input()` in Python is always treated as a string, so it must be converted to the appropriate data type using functions like `float()` or `int()`.

In the context of the exercise, you ask the user to enter numbers. This input is then stored in variables, and appropriate type conversion is done to treat them as numeric values. Here’s an example:
  • `num1 = float(input("Enter the first number: "))`
  • `num2 = float(input("Enter the second number: "))`
  • `num3 = float(input("Enter the third number: "))`
This ensures that whatever numerical input the user provides is ready for arithmetic operations or comparisons.
Comparing Variables in Python
Variable comparison is a fundamental operation in programming, allowing the code to evaluate which variables or values meet certain conditions. In Python, comparison operators such as `>`, `<`, `==`, etc., come in handy.

With the exercise at hand, after inputting and storing the floating-point numbers, the next challenge is comparison. You use the `>` operator to continually compare the numbers:
  • First, assume the first number is the largest.
  • Then, check if the second number is larger using `if num2 > largest:`.
  • Again, check if the third number is larger with `if num3 > largest:`.
Each comparison updates the value of a variable that tracks the greatest number found so far, eventually leading to identifying the largest number among the three inputs.

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Write a program that reads a temperature value and the letter \(C\) for Celsius or \(F\) for Fahrenheit. Print whether water is liquid, solid, or gaseous at the given temperature at sea level.

Suppose \(x\) and y are variables each of which contains a number. Write a code fragment that sets y to the absolute value of \(x\) without calling the abs function. Use an if statement.

A minivan has two sliding doors. Each door can be opened by cither a dashboard switch, its inside handle, or its outside handle. However, the inside handles do not work if a child lock switch is activated. In order for the sliding doors to open, the gear shift must be in park, and the master unlock switch must be activated. (This book's author is the long-suffering owner of just such a vehicle.) Your task is to simulate a portion of the control software for the vchicle. The input is a sequence of values for the switches and the gear shift, in the following order: \- Dashboard switches for left and right sliding door, child lock, and master unlock (O for off or 1 for activated) \- Inside and outside handles on the left and right sliding doors (O or 1) A the gear shift setting (one of P N D \(123 \mathrm{R}\) ). Print "left door opens" and/or "right door opens" as appropriate. If neither door opens, print "both doors stay closed".

French country names are feminine when they end with the letter \(e\), masculine otherwise, except for the following which are masculine even though they end with e: \- Ie Belize \- le Cambodge \- le Mexique \- le Mozambique \- leZaire \- leZimbabwe Write a program that reads the French name of a country and adds the article: le for masculine or la for feminine, such as le Canada or la Belgique. However, if the country name starts with a vowel, use l'; for example, l'Afghanistan. For the following plural country names, use les: \- Ies Etats-Unis \- les Pays-Bas

Roman numbers. Write a program that converts a positive integer into the Roman number system. The Roman number system has digits \(\begin{array}{ll}\text { I } & 1 \\ \text { V } & 5 \\ \text { X } & 10 \\\ \text { L. } & 50 \\ \text { C } & 100 \\ \text { D } & 500 \\ \text { M } & 1,000\end{array}\) Numbers are formed according to the following rules: a. Only numbers up to 3,999 are represented. b. As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. c. The numbers 1 to 9 are expressed \(\begin{array}{ll}\text { I } & \text { 1 } \\ \text { II } & 2 \\ \text { III } & 3 \\ \text { IV } & 4 \\ \text { V } & 5 \\ \text { VI } & 6 \\\ \text { VII } & 7 \\ \text { VIII } & 8 \\ \text { IX } & 9\end{array}\) As you can see, an I preceding a \(V\) or \(X\) is subtracted from the valuc, and you can never have more than three I's in a row. d. Tens and hundreds are done the same way, except that the letters \(\mathrm{X}, \mathrm{L}, \mathrm{C}\) and \(\mathrm{C}\), \(\mathrm{D}, \mathrm{M}\) are used instead of \(\mathrm{I}, \mathrm{V}, \mathrm{X}\), respectively. Your program should take an input, such as 1978 , and convert it to Roman numerals, MCMLXXVIII.

See all solutions

Recommended explanations on Computer Science Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.