Can anyone help me with the below programs: A) which returns orger summary as a list with 2- tuples. Each tuple consists of the order number and the product of the price per items and the quantity. OUTPUT: [ ('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97) ]. 10 INR should be increased in the product if the value of the order is smaller than 100.00 INR. OUTPUT: [ ('34587',163.8),('98762',284.0),(77226',108.85),('88112',84.97) ]

Asked by Last Modified  

24 Answers

+3 Python Python Anaconda Python Advanced

Follow 7
Answer

Please enter your answer

Build Yourself For The Future

Can't solve because product price is a part of the tuple. Since LIST IS MUTABLE so we can change its elements. We can change the whole tuple because it is an element of the list. As WKT TUPLE IS IMMUTABLE so we can't change its elements.
Comments

Senior Software Engineer/Java Full Stack Developer.

public class DemoApplication { public static void main(String args) { //SpringApplication.run(DemoApplication.class, args); List<Order> list=new ArrayList(); list.add(new Order("34587", 163.8)); list.add(new Order("98762", 284.0)); list.add(new Order("77226", 98.85)); list.add(new Order("88112",...
read more
public class DemoApplication { public static void main(String[] args) { //SpringApplication.run(DemoApplication.class, args); List<Order> list=new ArrayList(); list.add(new Order("34587", 163.8)); list.add(new Order("98762", 284.0)); list.add(new Order("77226", 98.85)); list.add(new Order("88112", 74.97)); System.out.println("Before Processing List orders :: "+list); int index=-1; for(Order order: list) { index++; if(order.getPrice()<100) { order.setPrice(order.getPrice()+10); list.set(index, order); } } System.out.println("After processing List orders :: "+list); } } class Order{ private String orderNo; private double price; public Order(String orderNo, double price) { super(); this.orderNo = orderNo; this.price = price; } public void setOrderNo(String orderNo){ this.orderNo=orderNo; } public String getOrderNo(){ return orderNo; } public void setPrice(double price){ this.price=price; } public double getPrice(){ return price; } @Override public String toString() { return "Order [orderNo=" + orderNo + ", price=" + price + "]"; } } read less
Comments

IT Professional with 2 years of experience

Hello Anurag, As per your question, Input:- a list of tuples with two values (order-number: string, total-order-cost: float) each Output:- the updated list of tuples. Condition: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of...
read more
Hello Anurag, As per your question, Input:- a list of tuples with two values (order-number: string, total-order-cost: float) each Output:- the updated list of tuples. Condition: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of (a, b) in the input list. Program: 1) With regular for-loop: # You might use list(input()) to read list from user input. inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)] outputList = [] for _tuple in inputList: if (_tuple[1] < 100): outputList.append((_tuple[0], _tuple[1]+10)) else: outputList.append((_tuple[0],_tuple[1])) print('Updated List:',outputList) PS: Since tuples are immutable (cannot change it's value further) in python, we used one more list instead of replacing the given input list itself. 2) With list-comprehension:- inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)] def getUpdatedList(inputList): return [(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList] outputList = getUpdatedList(inputTuple) print(outputList) Or simply, print([(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList]) Feel free to ask me any further questions. Happy Coding!!! read less
Comments

IT Professional with 2 years of experience

Hello Anurag, As per your question, Input:- a list of tuples with two values (order-number: string, total-order-cost: float) each Output:- the updated list of tuples. Condition: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of...
read more
Hello Anurag, As per your question, Input:- a list of tuples with two values (order-number: string, total-order-cost: float) each Output:- the updated list of tuples. Condition: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of (a, b) in the input list. Program: 1) With regular for-loop: # You might use list(input()) to read list from user input. inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)] outputList = [] for _tuple in inputList: if (_tuple[1] < 100): outputList.append((_tuple[0], _tuple[1]+10)) else: outputList.append((_tuple[0],_tuple[1])) print('Updated List:',outputList) PS: Since tuples are immutable (cannot change it's value further) in python, we used one more list instead of replacing the given input list itself. 2) With list-comprehension:- inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)] def getUpdatedList(inputList): return [(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList] outputList = getUpdatedList(inputTuple) print(outputList) Or simply, print([(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList]) Feel free to ask me any further questions. Happy Coding!!! read less
Comments

IT Professional with 2 years of experience

Hello Anurag, As per your query, Input:- a list of tuples with two values (order-number: string, total-order-cost: float) each Output:- the updated list of tuples. Condition: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of (a,...
read more
Hello Anurag, As per your query, Input:- a list of tuples with two values (order-number: string, total-order-cost: float) each Output:- the updated list of tuples. Condition: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of (a, b) in the input list. Program: 1) With regular for-loop: # You might use list(input()) to read list from user input. inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)] outputList = [] for _tuple in inputList: if (_tuple[1] < 100): outputList.append((_tuple[0], _tuple[1]+10)) else: outputList.append((_tuple[0],_tuple[1])) print('Updated List:',outputList) PS: Since tuples are immutable (cannot change it's value further) in python, we used one more list instead of replacing the given input list itself. 2) With list-comprehension:- inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)] def getUpdatedList(inputList): return [(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList] outputList = getUpdatedList(inputTuple) print(outputList) Or simply, print([(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList]) Feel free to ask me any further questions. Happy Coding!!! read less
Comments

IT Professional with 2 years of experience

Hello Anurag, As per your query, Input:- a list of tuples with two values (order-number: string, total-order-cost: float) each Output:- the updated list of tuples. Condition: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of (a,...
read more
Hello Anurag, As per your query, Input:- a list of tuples with two values (order-number: string, total-order-cost: float) each Output:- the updated list of tuples. Condition: When b < 100, b = b + 10 where b: total-order-cost (product of the price per items and the quantity) for every tuple of (a, b) in the input list. Program: 1) With regular for-loop: # You might use list(input()) to read list from user input. inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)] outputList = [] for _tuple in inputList: if (_tuple[1] < 100): outputList.append((_tuple[0], _tuple[1]+10)) else: outputList.append((_tuple[0],_tuple[1])) print('Updated List:',outputList) PS: Since tuples are immutable (cannot change it's value further) in python, we used one more list instead of replacing the given input list itself. 2) With list-comprehension:- inputList = [('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97)] def getUpdatedList(inputList): return [(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList] outputList = getUpdatedList(inputTuple) print(outputList) Or simply, print([(ele[0], ele[1]+10) if (ele[1]) < 100 else (ele[0], ele[1]) for ele in inputList]) Feel free to ask me any further questions. Happy Coding!!! read less
Comments

Pyhton Djabgo Flask Trainer (7618030342)

Hi, Anurag, You can use List comprehension if the input list is lst then, lst = new_lst =
Comments

I am an entrepreneur and have more than 35 years of experience in the IT industry

Hello Anurag, Here is a simpler solution ... OUTPUT = oL, OUTPUTL = , oT = () for i in range(len(OUTPUT)): # convert the tuple to list oL.append(list(OUTPUT)) if oL < 100.00: # make the changes to the price oL += 10.00 # convert the list back to tuple ...
read more
Hello Anurag, Here is a simpler solution ... OUTPUT = [ ('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97) ] oL, OUTPUTL = [], [] oT = () for i in range(len(OUTPUT)): # convert the tuple to list oL.append(list(OUTPUT[i])) if oL[i][1] < 100.00: # make the changes to the price oL[i][1] += 10.00 # convert the list back to tuple oT = tuple(oL[i]) # append the tuple to the list OUTPUTL.append(oT) # overwrite the original OUTPUT OUTPUT = OUTPUTL print("OUTPUT", OUTPUT) read less
Comments

I am an entrepreneur and have more than 35 years of experience in the IT industry

OUTPUT = oL, OUTPUTL = , oT = ()for i in range(len(OUTPUT)): # convert the tuple to list oL.append(list(OUTPUT)) if oL < 100.00: # make the changes to the price oL += 10.00 # convert the list back to tuple oT = tuple(oL) # append the tuple to the list OUTPUTL.append(oT)#...
read more
OUTPUT = [ ('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97) ] oL, OUTPUTL = [], []oT = ()for i in range(len(OUTPUT)): # convert the tuple to list oL.append(list(OUTPUT[i])) if oL[i][1] < 100.00: # make the changes to the price oL[i][1] += 10.00 # convert the list back to tuple oT = tuple(oL[i]) # append the tuple to the list OUTPUTL.append(oT)# overwrite the original OUTPUTOUTPUT = OUTPUTLprint("OUTPUT", OUTPUT) read less
Comments

I have cracked IES exam,GATE,many PSU. And I would love to deliver the knowledge I have got.

Hi Anurag, Hope You are doing well with your coding, As per your requirement, # this is the input OUTPUT= # this is the output list in which your output will come ol= for i in OUTPUT: if i<100 : ol.append((i,i+10)) else: ol.append((i,i)) print(ol) Because Tuples are immutable,An...
read more
Hi Anurag, Hope You are doing well with your coding, As per your requirement, # this is the input OUTPUT= [ ('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97) ] # this is the output list in which your output will come ol=[] for i in OUTPUT: if i[1]<100 : ol.append((i[0],i[1]+10)) else: ol.append((i[0],i[1])) print(ol) Because Tuples are immutable,An Empty list has been taken to fill the required output. I hope this piece of code solves your problem.Actually it can be solved in other ways also. Regards Deepak read less
Comments

View 22 more Answers

Related Questions

Is coaching a good option in class 11?
Yes. Definitely it's always nice to have teachers guiding you . But one should never depend on classes completely . Make sure you clear your doubts and basic concepts if you join any class . If the course...
Divya
0 0
5
What if I join coaching for IIT JEE in class 12 and not in class 11. Will I still have clear cut concepts in class 11?
U can join .. but the pressures wud increase as u have to cover 2 yr syllabus in one yr .. so its bttr to strt earlyy as possible But if u can cope up n handle pressure .u r gud to go
Gowrikanth
0 0
6
Which is best laptop for btech students?
GO FOR ANY BRAND WITH MINIMUM I3 PROCESSOR 8GB RAM (BECZ ACCORDING NEW SYLABUS YOU MAY REQUIRE FOR SOME OF THE SOFTWARES) 1 TB HDD
Medha
0 0
6
What is electricity?
Electricity is flow of Electron
Nomal
Which technology is better to learn for doing project for campus drive placement.either web development or Android?
Both are good and have their own importance. It depends on your interest also. I think what ever technology u will choose be a proficient in that technology that is important . Android is more popular...
K

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Semiconductor
Intrinsic Semiconductor :It is a pure Semiconductor which acts as an insulator at low temperature and acts as a Conductor at high temperature. Hence it is not used in developing electronic devices. Doping:...

Drag And Its Classifications
Introduction Drag is the enemy of flight and its cost. One group of those forces is aerodynamic forces that split into two forces: Lift force or lift, and Drag force or drag. A pre-requisite to aircraft...

JAVA OOPs Concepts (Object-Oriented Programming System)
JAVA OOPs Concepts (Object-Oriented Programming System) It is primarily having below crucial points. Without below essential points, we will never be able to achieve OOPs in java, PHP, C#, etc. Now let...

The Basic about modeling anything into CAD
The most basic problem that a beginner designer faces is - " From where to start" Have you ever wondered while starting to design an object to where should I start from or How am I suppose to know...

Disc and Drum Brake Difference
A

Arnab Bhattacharjee

0 0
0

Recommended Articles

According to a recent survey conducted by the NCAER (National Council of Advanced Economic Research), engineering is the most sought after course in India. Some engineering courses are offered as BE or Bachelor of Engineering while some as Bachelor in Technology or B.Tech. Since engineering is a professional course, the...

Read full article >

MBA, Medicine and engineering are the three main professional courses in India. Engineering is still one of the highly sorted after professional courses in the under graduate level, while MBA is favoured as a preferred post graduate course. To shine in these courses, one needs to work and study hard. Engineering as a...

Read full article >

Appearing for exams could be stressful for students. Even though they might have prepared well, they could suffer from anxiety, tension etc. These are not good for their health and mind. However, following a few exam preparation tips can save them from all these and help them to score good marks. Let’s find out all...

Read full article >

With the current trend of the world going digital, electronic renaissance is a new movement that is welcomed by the new generation as it helps makes the lives of millions of people easier and convenient. Along with this rapidly changing movement and gaining popularity of Internet, e-Learning is a new tool that emerging...

Read full article >

Looking for BTech Tuition ?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you