Exercise 42

Create a Python program that prompts the user to input numbers separated by semicolons ';'. The program should then convert the input into a list of integers.

Solution

# ask the user to enter numbers separated by semicolons ';'
input_str = input("Enter numbers separated by semicolons ';': ")

# initialize the requested list
num_list = input_str.split(';')

# building the requested list 
num_list = [int(num) for num in num_list]

# disply the result
print("List of numbers:", num_list)
"""
output:
Enter numbers separated by semicolons ';': 1;2;3;4;5
List of numbers: [1, 2, 3, 4, 5]
"""





 

Younes Derfoufi
my-courses.net

One thought on “Solution Exercise 42: python algorithm which create a list from entered numbers”

Leave a Reply