Question

def createList(): user_input = input("Enter a numbers seperated by a comma:") user_list = user_input.split(',') return user_list...

def createList():
user_input = input("Enter a numbers seperated by a comma:")
user_list = user_input.split(',')
return user_list
def remove_duplicates(user_list):
test = []
for i in user_list:
if i not in test:
test.append(i)
x= print("Original List :",user_list)
y= print("List after removing duplicates:", test)
return x,y
def main():
createList()
remove_duplicates(user_list)
main()

why isnt user_data being passed through to remove_duplicates(user_list)? Explanation too please

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This is because you were not capturing the user_list returned by the method createList().

Modified Code

def createList():

user_input = input("Enter a numbers seperated by a comma:")

user_list = user_input.split(',')

return user_list

def remove_duplicates(user_list):

test = []

for i in user_list:

if i not in test:

test.append(i)

x= print("Original List : ",user_list)

y= print("List after removing duplicates:", test)

return x,y

def main():

user_list = createList() ## only change that I did

remove_duplicates(user_list)

main()

Add a comment
Know the answer?
Add Answer to:
def createList(): user_input = input("Enter a numbers seperated by a comma:") user_list = user_input.split(',') return user_list...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX =...

    Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX = 100 #gets an integer def getValidInt(MINN, MAXX):     message = "Enter an integer between" + str(MINN) + "and" + str(MAXX)+ "(inclusive): "#message to ask the user     num = int(input(message))     while num < MINN or num > MAXX:         print("Invalid choice!")         num = int(input(message))     #return result     return num #counts dupes def twoInARow(numbers):     ans = "No duplicates next to each...

  • #function to covert kilometer to miles #takes km input as an argument and return the calculation...

    #function to covert kilometer to miles #takes km input as an argument and return the calculation def kilometer_to_miles(km): return km * 0.6214 #function to covert miles to kilometer #takes miles input as an argument and return the calculation def miles_to_kilometer(miles): return miles/0.6214 #Main function to find the distance #by calling either of the two functions #prompt the user to enter his/her choice of distance conversion restart = 0 while (restart == 'y'): user_input = input ("Enter k to convert kilometer...

  • Can you please enter this python program code into an IPO Chart? import random def menu():...

    Can you please enter this python program code into an IPO Chart? import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the computer can guess it\n3. Exit") while True: #using try-except for the choice will handle the non-numbers #if user enters letters, then except will show the message, Numbers only! try: c=int(input("Enter your choice: ")) if(c>=1 and c<=3): return c else: print("Enter number between 1 and 3 inclusive.") except: #print exception print("Numbers Only!")...

  • I am trying to finish the code below. class DVD: def __init__(self, title, dvd_type, cost): self.title = title self.dvd_type = dvd_type self.cost = cost def setTitle(self, netTitle): self.title = newT...

    I am trying to finish the code below. class DVD: def __init__(self, title, dvd_type, cost): self.title = title self.dvd_type = dvd_type self.cost = cost def setTitle(self, netTitle): self.title = newTitle def getTitle(self): return self.title def getType(self): return self.dvd_type def getCost(self): return self.cost def setCost(self, newCost): self.cost = newCost def setType(self, newdvd_Type): validTypes = ['Game', 'Word', 'Compiler', 'Spreadsheet', 'dBase', 'Presentation'] while True: self.dvd_type = input( 'Please enter the valid type: (Game, Word, Compiler, Spreadsheet, dBase, Presentation)') if self.dvd_type() not in validTypes:...

  • This works as expected BUT when I enter a input that is incorrect more than one...

    This works as expected BUT when I enter a input that is incorrect more than one time, the second time it stops works. It works as expected and redisplays the prompt after the first time an exception is raised but crashes the second. Any help appreciated! ------------------------------------------------------------------------- # This program will open and read a list of numbers in a text file and then terminate def nums():    prompt = input("Please enter the name of your file: ")      read_numbers...

  • Look at the following function definition: def my_function(x, y): return x[y] a. Write a statement that...

    Look at the following function definition: def my_function(x, y): return x[y] a. Write a statement that calls this function and uses keyword arguments to pass ‘testing’ into x and 2 into y. b. What will be printed when the function call executes? 6. Write a statement that generates a random number in the range I'm using python to solve this this is what i did def main():      result= my_function(x='testing', y=2)      print(result) def my_function(x,y):      return x[y] main()

  • In this assignment, you will revisit reading data from a file, and use that data as...

    In this assignment, you will revisit reading data from a file, and use that data as arguments (parameters) for a number of functions you will write. You will need to: Write and test a function square_each(nums) Where nums is a (Python) list of numbers. It modifies the list nums by squaring each entry and replacing its original value. You must modify the parameter, return will not be allowed! Write and test a function sum_list(nums) Where nums is a (Python) list...

  • def get_average_club_count(person_to_clubs: Dict[str, List[str]]) -> float: """Return the average number of clubs that a person in...

    def get_average_club_count(person_to_clubs: Dict[str, List[str]]) -> float: """Return the average number of clubs that a person in person_to_clubs belongs to. >>> get_average_club_count(P2C) 1.6 >>> get_average_club_count({'Bob': ['X', 'Y'], 'John': []}) 1.0 """ This is the function I need to test for edge cases, I need to have a test case such that it will detect that the input has been modified(mutation). What test case would I implement?

  • I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to...

    I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to guess its because I'm not using the swap function I built. Every time I run it though I get an error that says the following Traceback (most recent call last): File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 146, in <module> main() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 122, in main studentArray.gpaSort() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py",...

  • 2. Consider the following function # listOfNumbers is a list of only numbers # def processList(listOfNumbers):...

    2. Consider the following function # listOfNumbers is a list of only numbers # def processList(listOfNumbers): result = [] for i in listOfNumbers: if i<0 == 0: result.append(i*i) else: result.append((i*i)+1) return result First, study and test processList(listOfNumbers) to determine what it does Then rewrite its body so that it accomplishes the same task with a one-line list comprehension. Thus, the resulting function will have exactly two lines, the def line and a return line containing a list comprehension expression. 3....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT