Input a List using Loops in Python

preview_player
Показать описание
Python Programming: Input a List using Loops in Python
Topics discussed:
1. Problem associated with the input() Method.
2. Input a List using Loops.

Music:
Axol x Alex Skrindo - You [NCS Release]

#PythonByNeso #PythonProgramming #ListsInPython
Рекомендации по теме
Комментарии
Автор

Sir, instead of using for loop to input a list we can use split function...

numbers = input().split()

CHAITANYAB-cv
Автор

@Neso academy Great video, it helps me a lot as usual but what about if we want a list which is a collection of different types of items ? because with the example in the course all the items of our list must be an integer

lionelfaith
Автор

This can also be achieved using below code for storing items as string not int.

items = input("Enter multiple items: ")
list = items.split()
print(list)

handle_gc
Автор

Thanks for the vid. Just a suggestion… what if you need to input hundreds of numbers? The user is not going to want take a count of each number and possibly miscount.
Might be better just to input numbers and type END when finished.

fifthamendment
Автор

x=int(input()). I am getting ValueError:Inavlid literal for int() with base 10 . Why

Proffs.Design
Автор

sir i have a doubt
can't we directly use eval function for entering the list
sir i had tried it and also work so why to use loop method

pawansaxena
Автор

what about this code ?

numbers = [ ]
for i in range(3):
x = input('Enter the element: ')
numbers.append(x)
print(numbers)

alimuhtasham
Автор

n=int(input("enter the number of elements of your list: ")) #input data from the user and convert it to integer type
numbers=[] #create an empty list
for i in range(n): #iterate my list from index 0 to n-1 and repeat the block of instructions below for each i
x = int(input(f"enter the elements for numbers {[i]}: ")) #store the elements of the list from user in x variable
numbers.append(x) #add each element at the end of the list numbers
print(numbers) #output the new list

lionelfaith
Автор

Please use an ide... Command prompt sucks

internetguy