[Solved] why am I getting this erroneous output?

If i understand the problem correctly it should take first int then scan the n lines and creating sort of 2 dimension list/array or so then should accept int of questions about what is in position (x,y) in this 2 dimensional object covering what is out of bounds as an “ERROR!”. import java.util.ArrayList; import java.util.Scanner; … Read more

[Solved] why am I getting this erroneous output?

Introduction If you are getting an erroneous output when running a program, it can be a frustrating experience. It can be difficult to determine the cause of the problem and even more difficult to find a solution. This article will provide an overview of the most common causes of erroneous output and provide tips on … Read more

[Solved] Rainbow Array on Python

Here is a basic example. rainbow = [‘Program Ended’, ‘Red’, ‘Orange’, ‘Yellow’, ‘Green’, ‘Blue’, ‘Indigo’] user_input = int(input(“Please select a number between 1 and 6: “)) if user_input > 0 and user_input < 7: print(rainbow[user_input]) else: print(“Program ended”) To capture a user’s input, you simply invoke: input() function. To access an array, you can do … Read more

[Solved] Two list count specific elements and aggregate on spefic rule [closed]

There are many possible solutions. In my opininion this is the easiest: import heapq list1 = [2,5,7] list2=[4,6,9] counter1=0 counter2=0 sum1=0 sum2=0 full_list = list1 + list2 three_largest = heapq.nlargest(3,full_list) for n in three_largest: if n in list1: list1.remove(n) counter1+=1 sum1+=n else: list2.remove(n) counter2+=1 sum2+=n print(counter1) print(counter2) print(sum1) print(sum2) Note that you made a mistake … Read more

[Solved] How to sort python dictionary/list?

Assuming I understood your question, these should do it: for person in sorted(cat1): print(person, max(cat1.get(person))) result: ben 9 jeff 6 sam 9 then: for person in sorted(cat1, key=lambda x: max(cat1.get(x)), reverse=True): print(person, max(cat1.get(person))) result: ben 9 sam 9 jeff 6 then: for person in sorted(cat1, key=lambda x: sum(cat1.get(x))/len(cat1.get(x)), reverse=True): print(person, sum(cat1.get(person))/len(cat1.get(person))) result: ben 7.666666666666667 sam … Read more

[Solved] Object created from a list of values

I think this is what you need.I have commented the code for your understanding import java.util.ArrayList; import java.util.List; public class demo { public static void main(String[]args){ List<Integer>list1=new ArrayList<Integer>(); List<Integer>list2=new ArrayList<Integer>(); List<Integer>list3=new ArrayList<Integer>(); ////here add your values to the list,i have not added them.You first need to add the values to the list //then iterate through … Read more