Python Exercise 4 Problem
In this Python exercise, write a program that will accept a user input with numbers and generate a list and tuple with the provided input numbers. A hint for this exercise is create the list first and split the numbers before creating a tuple of the numbers given.
Note: This Python exercise in completed in Python version 3.7.
Python Exercise 4 Solution
Python Code Input:
1 2 3 4 5 6 7 8 9 10 11 12 | number_values = input("Provide a sequence of numbers separated by commas: ") list_number_values = number_values.split(",") tuple_number_values = tuple(list_number_values) print(f"\nThis is a printed list of the number values: ") print(f"\t{list_number_values} ") print("\nThis is a printed tuple of the number values: ") print(f"\t{tuple_number_values} ") print("""\nAt first glance you may notice the list and tuple look the same, but the list uses brackets and the tuple uses parenthesis.""") |
User Input:
1 | Provide a sequence of numbers separated by commas: 2,4,8,16,32,64 |
Python Code Output:
1 2 3 4 5 6 7 8 | This is a printed list of the number values: ['2', '4', '8', '16', '32', '64'] This is a printed tuple of the number values: ('2', '4', '8', '16', '32', '64') At first glance you may notice the list and tuple look the same, but the list uses brackets and the tuple uses parenthesis. |