-1

I want to remove the quotes from the variable average. Here is my code:

list_1 = ['LIST: ']
list_2 = [['Mary Smith', 132, 'Jean Jones', 156, 'Karen Karter', 167]]
list_3 = ['Mary Smith', 132, 'Jean Jones', 156, 'Karen Karter', 167]
combine = (str(list_1)[2:-2]) + (str(list_2)[1:-1])
print(combine)
new_list = input("Name to add to the list: ")
average = input("Average: ")
list_3.append(new_list)
list_3.append(average) 
print(f"UPDATED LIST: {list_3}")
print("There are now {0} items".format(len(list_3)), "in  the list")

Here is what I want to come out:

LIST: ['Mary Smith', 132, 'Jean Jones', 156, 'Karen Karter', 167]
Name to add to the list: Ann Kert
Average: 189
UPDATED LIST: ['Mary Smith', 132, 'Jean Jones', 156, 'Karen Karter', 167, 'Ann Kert', 189]
There are now 8 items in  the list 

But here is what I got:

LIST: ['Mary Smith', 132, 'Jean Jones', 156, 'Karen Karter', 167]
Name to add to the list: Ann Kert
Average: 189
UPDATED LIST: ['Mary Smith', 132, 'Jean Jones', 156, 'Karen Karter', 167, 'Ann Kert', '189']
There are now 8 items in  the list

If you don't see the difference then the difference is the 189 needs to have no qoutes but the thing that I got is '189'

  • 1
    Welcome to StackOverflow! With `input` you got a string value '189'. And I suppose that you want integer value, e.g. `int('189')` - right? – Alex Yu Jun 16 '21 at 10:40
  • `combine = (str(list_1)[2:-2]) + (str(list_2)[1:-1])` this is one of the weirdest Python lines I saw. Probably you wanted `print('LIST:', list_2[0])` or `print('LIST:', list_3)` – Yuri Khristich Jun 16 '21 at 10:58

1 Answers1

3

Try type casting the string into int.

average = int(input("Average: "))
Mohammad Atif
  • 216
  • 1
  • 4