Answer to Question #303971 in Python for ratul

Question #303971

Suppose you went to a coffee shop and you want to drink some coffee. You


decided to drink n cup of coffee, where n is an integer value greater than


0. Now you have to pay m taka for the first cup of coffee, 2m taka for the


second cup, 3m takas for the third cup, and so on. In other words, you have


to pay i*m taka for the i-th cup of coffee.



Now you have k taka in your pocket. How many takas do you need to borrow


from your friend to buy n cup of coffee?



The first input in the sample input contains the cost of the first cup of


coffee which can be denoted as m. The second input is the number of coffees


you want to drink, n. The third input is k, the initial amount of taka you


have. You have to calculate how much money you have to borrow from your


friend. If you have more or equal amount of money that is needed than print


0.




1
Expert's answer
2022-02-28T13:54:24-0500
n=0
while(n<=0):
    n = int(input("Enter n no. of coffie: "))


m=0
while(m<=0):
    m = int(input("Enter m  taka value: "))


k=-1
while(k<0):
    k = int(input("Enter k taka in your pocket: "))


Sum = 0
for r in range(1,n+1):
    Sum = Sum + (r*m)
print("Total cost of ",n,"no. of coffie = ",Sum)


if(k >=Sum):
    print("No amount needs to be borrowed")
else:
    print("Amount to be borrowed: ",Sum-k)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS