Home / Programs / Accept a list of 5 float numbers as an input from the user
🚀 Programming Example

Accept a list of 5 float numbers as an input from the user

👁 1,402 Views
💻 Practical Program
📘 Step Learning

Write a python program to accept a list of 5 float numbers as an input from the user and show them as output.

📌 Information & Algorithm

Expected Output:

[78.6, 78.6, 85.3, 1.2, 3.5]

Hints:

  • Create a list variable named numbers
  • Run loop five times
  • In each iteration of the loop, use the input() function to take input from a user
  • Convert user input to float number using the float() constructor
  • Add float number to the numbers list using the append() function

💻 Program Code

numbers = []

# 5 is the list size
# run loop 5 times
for i in range(0, 5):
    print("Enter number at location", i, ":")
    # accept float number from user
    item = float(input())
    # add it to the list
    numbers.append(item)

print("User List:", numbers)
                        

🖥 Program Output

Enter number at location 0 :
12
Enter number at location 1 :
34
Enter number at location 2 :
56
Enter number at location 3 :
78
Enter number at location 4 :
76
User List: [12.0, 34.0, 56.0, 78.0, 76.0]
                            
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.