Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 with input remove a string from the list
#1
Hello,

i cant quite figure why this code doesnt work Wall

friends = ["Kevin", "Karen", "jim", "Oscar", "Toby"]
variable = input("Delete Kevin? ")
if variable = yes:
    friends.remove("Kevin")
print(friends)
Yoriz wrote Oct-12-2019, 09:20 AM:
Please post all code, output and errors (in it's entirety) between their respective tags. I did it for you this time, Here are instructions on how to do it yourself next time.
Quote
#2
if variable = yes:
input returns a string, compare to a string of 'yes'
if variable = 'yes':
konsular likes this post
Quote
#3
= is assignment
== is equality
You need to use the second one

then you will get another error
because at the moment yes is a variable and is not defined. You want it to be string in order to compare with the user input
konsular likes this post
Quote
#4
thanks a lot!

especialy your explanation helped my a lot buran!
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Input while interation in a list doug2019 6 179 Oct-06-2019, 06:44 PM
Last Post: buran
  weird result trying to remove numbers from a list Exsul 6 200 Aug-27-2019, 05:10 AM
Last Post: perfringo
  Creating csv header from user-input list dvanommen 2 193 Aug-26-2019, 08:51 PM
Last Post: dvanommen
  How to remove multiples in a list jasper100125 6 254 Aug-20-2019, 06:38 AM
Last Post: buran
  Remove \n from list of values within a pandas columns klllmmm 2 319 Jun-24-2019, 05:16 AM
Last Post: klllmmm
  Remove \n at the end of a character from a list judkil 2 239 Jun-24-2019, 12:15 AM
Last Post: DeaD_EyE
  simple string & input problem kungshamji 5 322 Jun-23-2019, 03:54 PM
Last Post: kungshamji
  Forcing input from pre-defined list. scotty501 11 658 Jun-18-2019, 01:49 PM
Last Post: scotty501
  I converted string to 'list', but it doesn't look like a list! mrapple2020 3 394 Apr-07-2019, 02:34 PM
Last Post: mrapple2020
  remove string character from url jacklee26 10 862 Mar-25-2019, 03:56 PM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)