111k views
3 votes
Write a program that prompts a user to input three doubles and then prints these three doubles backward on the screen.

Write a program that prompts a user to input three doubles and then prints these three-example-1

1 Answer

6 votes

Answer:

This is the code in python

# Prompt the user to input three doubles

print("Please enter three doubles:")

a = float(input()) # Read the first double

b = float(input()) # Read the second double

c = float(input()) # Read the third double

# Print the three doubles backward on the screen

print("The three doubles backward are:")

print(c) # Print the third double

print(b) # Print the second double

print(a) # Print the first double

Step-by-step explanation:

This Python code is a simple program that prompts the user to input three decimal numbers (doubles), reads these numbers from the user's input, and then prints them out in reverse order.

Here's a step-by-step explanation of the code:

The program starts by displaying a message to the user, asking them to input three decimal numbers:

print("Please enter three doubles:")

The program uses the float() function to read the user's input as a floating-point number (decimal number) and assigns each input to variables a, b, and c respectively:

a = float(input()) # Read the first double

b = float(input()) # Read the second double

c = float(input()) # Read the third double

After reading the three input doubles, the program proceeds to print them out in reverse order using the print() function:

print("The three doubles backward are:")

print(c) # Print the third double

print(b) # Print the second double

print(a) # Print the first double

So, when you run this program and provide three decimal numbers as input, it will display those numbers in reverse order on the screen.

For example, if you input:

2.5

4.7

1.3

The program will output:

The three doubles backward are:

1.3

4.7

2.5

User Steffy
by
8.8k points

No related questions found