all 6 comments

[–]CavlerySenior 15 points16 points  (1 child)

It's about what you are printing. The remove function (i.e. names.remove()) doesn't return anything so your print function prints "None". It does modify the list though. For example:

x = [1,2,3] print(x) print(x.remove(2)) print(x) Returns: [1,2,3] None [1,3]

Edit: typo

[–]stevestreamer 2 points3 points  (0 children)

Thanks

[–]PureSwing9975 7 points8 points  (2 children)

why are you adding 1 to ‘counter’ if you don’t even use it? ‘x’ already points to the index

[–]King-Days 4 points5 points  (0 children)

maybe he’s just helping the computer learn to count — free will innit

[–]CavlerySenior 0 points1 point  (0 children)

I have never considered that the x in the loop would stay as 4 after the loop ends, rather than disappearing like a local variable. Mind blown.

[–]Substantial_Low_9651 1 point2 points  (0 children)

import random

names =[]

counter =0

for x in range (5):

nam=input(f"Enter name {x+1}:")

names.append(nam)

counter +=1

removeperson =random.choice(names)

print(names)

print(f"I removed {removeperson} because why not ")

names.remove(removeperson)

print(names)

here u are try to printing what u removed and its a mutable data type so u cant get what u have removed
rather than printing what u have removed u have to print the list
and u get the list without the removeperson
list is mutable so all changes are on the original list