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 other"
count = 0
i = 0
#go through the list
while i < len(numbers):
if numbers[i] ==
numbers[i+1]:
print("Found dupes next to each other:" + str(numbers[i]))#print
out the result if a dupe is found
i +=1
#compare things
def equiv(i1,i2):
result = ""
#if the same
if i1 == i2:
result = "They
match!"
#if not thesame
else:
result = "No
match"
return result
#avg
def average(numbers):
i = 0
while i < len(numbers):
i += 1
total += i
average = total / len(numbers)
#return average
return average
def main():
num = getValidInt(MINN,MAXX)
print("Thank you for choosing", num)
#check for duplicates next to each other
print("The result of the nearby duplicate
test:")
numbers = [1,0,4,4,3,2,6,2,7,8,9]
twoInARow(numbers)
print("There are",result,"matches")
result =
equiv(num1,numbers[len(numbers)-1])
print("The result of the equivalence test:",
result)
#calculate the average of the list
average = average(numbers)
print("The average is", average)
Please, can someone debug my code to give this sample output:
bash-4.1$ python fixed_lab10.py
Enter an integer between 1 and 100 (inclusive): 9
Thank you for choosing 9
The result of the nearby duplicate test:
Found dupes next to each other: 4
The result of the equivalence test: They match!
The average is 3.8
Solution:
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 other" count = 0 i = 0 # go through the list while i < len(numbers) - 1: if numbers[i] == numbers[i + 1]: print("Found dupes next to each other:" + str(numbers[i])) # print out the result if a dupe is found return numbers[i] i += 1 # compare things def equiv(i1, i2): result = "" # if the same if i1 == i2: result = "They match!" # if not thesame else: result = "No match" return result # avg def average(numbers): total = 0 n = len(numbers) for i in numbers: total = total + i total = total - twoInARow(numbers) return total / n def main(): num = getValidInt(MINN, MAXX) print("Thank you for choosing", num) # check for duplicates next to each other print("The result of the nearby duplicate test:") numbers = [1, 0, 4, 4, 3, 2, 6, 2, 7, 8, 9] twoInARow(numbers) result = equiv(num, numbers[len(numbers) - 1]) print("The result of the equivalence test:", result) # calculate the average of the list average1 = average(numbers) average1 = round(average1, 1) print("The average is", average1) main()
Output:
Please, I need help debuuging my code. Sample output is below MINN = 1 MAXX =...
PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...
PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList: def __init__(self): self.__head = None self.__tail = None self.__size = 0 def insert(self, i, data): if self.isEmpty(): self.__head = listNode(data) self.__tail = self.__head elif i <= 0: self.__head = listNode(data, self.__head) elif i >= self.__size: self.__tail.setNext(listNode(data)) self.__tail = self.__tail.getNext() else: current = self.__getIthNode(i - 1) current.setNext(listNode(data,...
11q Language is python need help 1) What is the output of the following code? Refer to the class defined here. Example: File 1: asset.py import asset class Asset: brains = asset.Asset( "Brains" ) strength = asset. Asset( "Strength" ) steel = asset.Asset( "Steel" ) wheelbarrow = asset. Asset( "Wheelbarrow" ) cloak = asset.Asset( "Cloak" ) def _init__( self, name): self.mName = name return def getName( self ): return self.mName al = strength + steel a2 = cloak + wheelbarrow...
YOU NEED TO MODIFY THE PROJECT INCLUDED AT THE END AND USE THE INCLUDED DRIVER TO TEST YOUR CODE TO MAKE SURE IT WORK AS EXPECTED. Thanks USING PYTHON, complete the template below such that you will provide code to solve the following problem: Please write and/or extend the project5 attached at the end. You will have to do the following for this assignment: Create and complete the methods of the PriceException class. Create the processFile function. Modify the main...
Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to run properly for the lab.. class ItemPurchase: def __init__(self, nameitem='none', item_prc=0, item_quntity=0, item_descrp = 'none'): self.nameitem = nameitem self.item_prc = item_prc self.item_quntity = item_quntity self.item_descrp = item_descrp def print_itemvaluecost(self): string = '{} {} @ ${} = ${}'.format(self.nameitem, self.item_quntity, self.item_prc(self.item_quntity * self.item_prc)) valuecost = self.item_quntity * self.item_prc return string, valuecost def print_itemdescription(self): string...
Use your Food class, utilities code, and sample data from Lab 1 to complete the following Tasks. def average_calories(foods): """ ------------------------------------------------------- Determines the average calories in a list of foods. foods is unchanged. Use: avg = average_calories(foods) ------------------------------------------------------- Parameters: foods - a list of Food objects (list of Food) Returns: avg - average calories in all Food objects of foods (int) ------------------------------------------------------- """ your code here is the...
Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to run properly for the lab.. class ItemPurchase: def __init__(self, nameitem='none', item_prc=0, item_quntity=0, item_descrp = 'none'): self.nameitem = nameitem self.item_prc = item_prc self.item_quntity = item_quntity self.item_descrp = item_descrp def print_itemvaluecost(self): string = '{} {} @ ${} = ${}'.format(self.nameitem, self.item_quntity, self.item_prc(self.item_quntity * self.item_prc)) valuecost = self.item_quntity * self.item_prc return string, valuecost def print_itemdescription(self): string = '{}: {}'.format(self.nameitem, self.item_descrp) print(string , end='\n') return string class Shopping_Cart: #Parameter...
My Python file will not work below and I am not sure why, please help me debug! ********************************* Instructions for program: You’ll use these functions to put together a program that does the following: Gives the user sentences to type, until they type DONE and then the test is over. Counts the number of seconds from when the user begins to when the test is over. Counts and reports: The total number of words the user typed, and how many...
[Using Python] I need my code given below to loop the user input, so that you are asked to input without it stopping after 4 inputs. Code: #A program that converts a hexadecimal number to its decimal value #Define function for hexadecimal to decimal def hexToDec(hexi): result = 0 #For loop to test input for correct values for char in hexi: if 'A' <= char <= 'F' or 'a' <= char <= 'f': if 'a' <= char <= 'f': result...
12p I need help this is Python EXCEPTIONS: It's easier to ask forgiveness than permission. Try the code and catch the errors. The other paradigm is 'Look before you leap' which means test conditions to avoid errors. This can cause race conditions. 1.Write the output of the code here: class MyError(Exception): pass def notZero(num): if num == 0: raise MyError def run(f): try: exec(f) except TypeError: print("Wrong type, Programmer error") except ValueError: print("We value only integers.") except Zero Division Error:...