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
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()

def createList(): user_input = input("Enter a numbers seperated by a comma:") user_list = user_input.split(',') return user_list...
The problem is this Design a function that accepts a list as an argument and returns the largest value in the list. The function should use recursion to find the largest item. My coding so far is this def main(): # Prints the largest value in list user_input = input('Enter a list of numbers seperated by a space: ') user_list = user_input.split() print('Largest number is ', max_Number(user_list), '.') # Recursion function that finds the maximum number in a sequence of...
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 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...
How to input a list from user def SameIntheList(): list1 = list(input("Enter list1:")) list2 = list(input("Enter list2:")) same_in_list = [] for i in list1: if i in list2: same_in_list.append(i) print(same_in_list) SameIntheList() ----------------- Enter list1:a,b,c Enter list2:a,b,g ['a', ',', 'b', ','] ---------------- I just want to display the same character in the 2 list ['a', 'b']
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 = 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 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 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()
The programs for this week will all take the form: def main(): collect the input for the arguments value = functionName(arguments) print(value) def functionName(arguments): code to solve the problem return value main() Write programs using functions to solve: • Write the following functions and provide a program to test them. Include descriptive statements that prompt the user for the the three input variables. b. def average(x, y, z) (returning th average of the arguments)
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...