I'm a beginner to Python 3 and when I try this code it works:
a = input('Enter three digits separated by space:')
b = a.split()
mylist = [int(i) for i in b]
print(mylist)
Output:
Enter three digits separated by space:2 3 4
[2, 3, 4]
However I get errors when I try this:
a = input('Enter three digits separated by space:')
b = a.split()
mylist = [int(i**2) for i in b]
print(mylist)
Error: TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'
In fact this works as well:
list1 = [2,3,4]
mylist = [int(i**2) for i in list1]
print(mylist)
What am I doing wrong?