Can someone fix this python program? I'm trying to do three things: Create a function that takes in a string as a parameter. Then create a dictionary of characters to integers, where the integer represents how many times the number of times the character appears in the word. Create a function that takes two lists as parameters and returns the elements they have in common of the two lists. Ask the user to create a list of numbers and keep asking them for entries until they enter a negative number. Then print the list and return the size of the list.
def getFreq(string):
freq={}
for i in string:
freq[i]=freq.setdefault(i,0)+1
return freq
def intersectLists(List1,List2):
common=[]
for i in List1:
if i in List2:
if i not in common:
common.append(i)
return common
def listOfNumbers():
List=[]
a=float(input('Enter number: '))
while a>=0:
List.append(a)
a = float(input('Enter number: '))
print(List)
return len(List)Can someone fix this python program? I'm trying to do three things: Create a function that...
Python. Write a function swap_lists that takes in two lists and swap their elements in place. You can not use another list. You can not return lists. Input lists have the same size. def swap_lists(alist1, alist2): """Swaps content of two lists. Does not return anything. >>> list1 = [1, 2] >>> list2 = [3, 4] >>> swap_lists(list1, list2) >>> print(list1) [3, 4] >>> print(list2) [1, 2] >>> list1 = [4, 2, 6, 8, 90, 45] >>> list2 = [30, 41,...
I try to define a PYTHON program that can print the largest
factor of the number except for the number itself. Ex: enter n as
15, the program will print: 5. The factor of 15 is 15, 5, 3, 1, but
15 will not be counted in this case. If enter a prime number, it
will print 1.
I am not sure what I did wrong here, please point out my mistake
and advise how should I improve.
def largest_factor(n)...
Write a python program write a function numDigits(num) which counts the digits in int num. Answer code is given in the Answer tab (and starting code), which converts num to a str, then uses the len() function to count and return the number of digits. Note that this does NOT work correctly for num < 0. (Try it and see.) Fix this in two different ways, by creating new functions numDigits2(num) and numDigits3(num) that each return the correct number of...
Something is preventing this python code from running properly.
Can you please go through it and improve it so it can work. The
specifications are below the code. Thanks
list1=[]
list2=[]
def add_player():
d={}
name=input("Enter name of the player:")
d["name"]=name
position=input ("Enter a position:")
if position in Pos:
d["position"]=position
at_bats=int(input("Enter AB:"))
d["at_bats"] = at_bats
hits= int(input("Enter H:"))
d["hits"] = hits
d["AVG"]= hits/at_bats
list1.append(d)
def display():
if len(list1)==0:
print("{:15} {:8} {:8} {:8} {:8}".format("Player", "Pos", "AB",
"H", "AVG"))
print("ORIGINAL TEAM")
for x...
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",...
Python: Create a function count_target_in_list that takes a list of integers and the target value then counts and returns the number of times the target value appears in the list. Write program in that uses get_int_list_from_user method to get a list of 10 numbers, then calls the count_target_list method to get the count then prints the number of times the target was found in the list. def get_int_list_from_user(): lst=[] y = int(input("Enter number of numbers")) for x in range(y): lst.append(int(input("Enter...
Python 3 Question: All I need is for someone to edit the program with comments that explains what the program is doing (for the entire program) def main(): developerInfo() #i left this part out retail = Retail_Item() test = Cash_Register() test.data(retail.get_item_number(), retail.get_description(), retail.get_unit_in_inventory(), retail.get_price()) answer = 'n' while answer == 'n' or answer == 'N': test.Menu() print() print() Number = int(input("Enter the menu number of the item " "you would like to purchase: ")) if Number == 8: test.show_items() else:...
Hello, In Python Enhance the prior assignment by doing the following 1) Create a class that contain all prior functions MyLib # This function adds two numbers def addition(a, b): return a + b # This function subtracts two numbers def subtraction(a, b): return a - b # This function multiplies two numbers def multiplication(a, b): return a * b # This function divides two numbers # The ZeroDivisionError exception is raised when division or modulo by zero takes place...
[Python] I have the following function that removes all non-numerical characters from a string: def remove_non_numeric(s): seq_type= type(s) return seq_type().join(filter(seq_type.isdigit, s)) And I need help implementing it into this function: def list_only_numbers( a_list ) : # Create a new empty list. # Using a loop (or a list comprehension) # 1) call remove_non_numeric with a list element # 2) if the return value is not the empty string, convert # the string to either int or float (if it contains...
In [: Secret extra credit assignment Do this entirely on your own! You may emalL me/swing by office hours for assistance dGetting o 189 and only a 188 on this wiLL boost your test score You WELL work on this L elther you get a 189 or break ends (whatever comes first) Do not submit on sokot, emdil me your Latest UT want you to succeed, these probLems should heLp tweak sone weaknesses and turn them into strengths! In [...