ARS Gems Store sells different varieties of gems to its customers.
Write a Python program to calculate the bill amount to be paid by a customer based on the list of gems and quantity purchased. Any purchase with a total bill amount above Rs.30000 is entitled for 5% discount. If any gem required by the customer is not available in the store, then consider total bill amount to be -1.Assume that quantity required by the customer for any gem will always be greater than 0.
Perform case-sensitive comparison wherever applicable.
def calculate_bill_amount(gems_list, price_list, reqd_gems, reqd_quantity):
price_dict = {gems_list[i]: price_list[i] for i in range(len(gems_list))}
reqd_dict = {reqd_gems[i]: reqd_quantity[i] for i in range(len(reqd_gems))}
try:
bill = sum(price_dict[gem] * reqd_dict[gem] for gem in reqd_dict)
except KeyError:
return -1
if bill > 30000:
bill = 0.95*bill
return bill
#List of gems available in the store
gems_list=['Amber', 'Aquamarine', 'Opal', 'Topaz']
#Price of gems available in the store. gems_list and price_list have one-to-one correspondence
price_list=[4392, 1342, 8734, 6421]
#List of gems required by the customer
reqd_gems=['Amber', 'Opal', 'Topaz']
#Quantity of gems required by the customer. reqd_gems and reqd_quantity have one-to-one correspondence
reqd_quantity=[2, 1, 3]
bill_amount=calculate_bill_amount(gems_list, price_list, reqd_gems, reqd_quantity)
print(bill_amount)
Write a python function, create_largest_number(), which accepts a list of numbers and returns the largest number possible by concatenating the list of numbers.
Note: Assume that all the numbers are two digit numbers.
Sample Input
Expected Output
23,34,55
553423
def create_largest_number(number_list): num="" number_list=sorted(number_list) for x in range(-1,-len(number_list)-1,-1): num+=str(number_list[x]) return int(num) number_list=[23,45,67] largest_number=create_largest_number(number_list) print(largest_number)#PF-Assgn-36 def create_largest_number(number_list): num="" number_list=sorted(number_list) for x in range(-1,-len(number_list)-1,-1): num+=str(number_list[x]) return int(num) number_list=[23,45,67] largest_number=create_largest_number(number_list) print(largest_number) Write a function, check_palindrome() to check whether the given string is a palindrome or not. The function should return true if it is a palindrome else it should return false.
Note: Initialize the string with various values and test your program. Assume that all the letters in the given string are all of the same case. Example: MAN, civic, WOW etc.
def check_palindrome(word): x=word[::-1] if x== word: return True else: return False status=check_palindrome("kik") if(status): print("word is palindrome") else: print("word is not palindrome")
0 Comments
Post a Comment