 true

Find the best tutors and institutes for BTech Tuition

Find Best BTech Tuition

No matching category found.

No matching Locality found.

Outside India?

Search for topics

# 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) ]

Tuition/BTech Tuition IT Courses/Programming Languages/Python IT Courses/Programming Languages/Python/Python Anaconda +1 IT Courses/Programming Languages/Python/Python Advanced less 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.

BCA, MCA, 11 and 12 computer science Trainer with more then 10 years of experience

Try this: t=l=len(t)t1= for i in range (l): if t<100: t1.append(,t+10)]) else: t1.append(,t)])t=t1 print(t) 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();

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 + "]";

}

}

Umapari Software Training Center Proprietor

Pythonized my previous answer: OUTPUT = oL = oL.extend()OUTPUT = oLprint(OUTPUT) read more

OUTPUT = [ ('34587',163.8),('98762',284.0),('77226',98.85),('88112',74.97) ]

oL = []
oL.extend([(id, price + 10) for id, price in OUTPUT if price < 100.00 or\
oL.append((id, price))])
OUTPUT = oL
print(OUTPUT)

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,

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 < 100):

outputList.append((_tuple, _tuple+10))

else:

outputList.append((_tuple,_tuple))

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, ele+10) if (ele) < 100 else (ele, ele) for ele in inputList]

outputList = getUpdatedList(inputTuple)

print(outputList)

Or simply,

print([(ele, ele+10) if (ele) < 100 else (ele, ele) for ele in inputList])

Feel free to ask me any further questions. Happy Coding!!!

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,

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 < 100):

outputList.append((_tuple, _tuple+10))

else:

outputList.append((_tuple,_tuple))

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, ele+10) if (ele) < 100 else (ele, ele) for ele in inputList]

outputList = getUpdatedList(inputTuple)

print(outputList)

Or simply,

print([(ele, ele+10) if (ele) < 100 else (ele, ele) for ele in inputList])

Feel free to ask me any further questions. Happy Coding!!!

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,

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 < 100):

outputList.append((_tuple, _tuple+10))

else:

outputList.append((_tuple,_tuple))

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, ele+10) if (ele) < 100 else (ele, ele) for ele in inputList]

outputList = getUpdatedList(inputTuple)

print(outputList)

Or simply,

print([(ele, ele+10) if (ele) < 100 else (ele, ele) for ele in inputList])

Feel free to ask me any further questions. Happy Coding!!!

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,

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 < 100):

outputList.append((_tuple, _tuple+10))

else:

outputList.append((_tuple,_tuple))

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, ele+10) if (ele) < 100 else (ele, ele) for ele in inputList]

outputList = getUpdatedList(inputTuple)

print(outputList)

Or simply,

print([(ele, ele+10) if (ele) < 100 else (ele, ele) for ele in inputList])

Feel free to ask me any further questions. Happy Coding!!!

Lets grow togther to change the world....

# Python code to sort a list of tuples # according to given key. # get the last key. def last(n): return n # function to sort the tuple def sort(tuples): # We pass used defined function last # as a parameter. return sorted(tuples, key = last) # driver code a = m = 2print("Sorted:"), print(sort(a))... read more

# Python code to sort a list of tuples
# according to given key.

# get the last key.
def last(n):
return n[m]

# function to sort the tuple
def sort(tuples):

# We pass used defined function last
# as a parameter.
return sorted(tuples, key = last)

# driver code
a = [(23, 45, 20), (25, 44, 39), (89, 40, 23)]
m = 2
print("Sorted:"),
print(sort(a))

Btech,JEEQualified,Studied from ALLEN, Kota, deliver lectures on MATHS & SCIENCE for class 10th

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)... read more

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 < 100):      outputList.append((_tuple, _tuple+10)) else:   outputList.append((_tuple,_tuple)) 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, ele+10) if (ele) < 100 else (ele, ele) for ele in inputList]   outputList = getUpdatedList(inputTuple) print(outputList)   Or simply,   print([(ele, ele+10) if (ele) < 100 else (ele, ele) for ele in inputList])

Feel free to ask me any further questions. enjoy coding.

Related Questions 01 Jun
56 6 days ago
259 08 Apr
17

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

Related Lessons

Pointers in C/C++
Many students have difficulty in understanding pointers. The best way to understand pointers is through memory representation. Whenever we declare a variable, the computer allocates some amount of memory... Yield criterion
Any increase of stress introduces deformations in the material which is recoverable to a point called elastic limit. Further increase in stress introduces permanent deformations called plastic deformations.... Find BE Tuition near you

Looking for BTech Tuition ?

Find best BTech Tuition in your locality on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

### Looking for BTech Tuition Classes?

Find best tutors for BTech Tuition Classes by posting a requirement.

• Post a learning requirement
• Get customized responses
• Compare and select the best  ### Looking for BTech Tuition Classes?

Find best BTech Tuition Classes in your locality on UrbanPro UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 25 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 6.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more