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...
I need help with my Java code. A user enters a sentence and the program will tell you what words were duplicated and how many times. If the same word is in the sentence twice, but one is capitalized, it will not count it as a duplicate. How can I make the program read the same word as the same word, even if one is capitalized and the other is not? For example, "the" and "The" should be counted as...
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...
Python : Need help with output of table Code: # Number of students print('How many students are in the class?') student_Number = int(input()) # Store list of students who are valid student_List = [] for i in range(0, student_Number): # To store current student data student_Data = [] print('Enter the name of student:') # Name of Students student_Name = input() if len(student_Name)> 24: print('Name of student cannot exceed 24 characters.') continue print('Enter the gpa of student:') # GPA of Student...
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...