Professional Documents
Culture Documents
Day1 5
Day1 5
#PF-Assgn-3
#This verification is based on string match.
mileage=12
amount_per_litre=40
distance_one_way=190
per_head_cost=0
divisible_by_five=False
#PF-Assgn-4
#This verification is based on string match.
#Day 1
principal=7800
rate_of_interest=7.7
time=26
interest=0
#Do not modify the below print statement for verification to work
print(interest)
#PF-Assgn-22
def find_leap_years(given_year):
list_of_leap_years=find_leap_years(2000)
print(list_of_leap_years)
#PF-Assgn-23
def calculate_bill_amount(gems_list, price_list, reqd_gems,reqd_quantity):
bill_amount=0
#Write your logic here
for gem in range(len(reqd_gems)):
if reqd_gems[gem] in gems_list:
index_of_price = gems_list.index(reqd_gems[gem])
else:
return -1
bill_amount += reqd_quantity[gem] * price_list[index_of_price]
if 30000 < bill_amount:
bill_amount -= bill_amount/20
return bill_amount
#Price of gems available in the store. gems_list and price_list have one-to-one correspondence
price_list=[1760,2119,1599,3920,3999]
#Quantity of gems required by the customer. reqd_gems and reqd_quantity have one-to-one
correspondence
reqd_quantity=[3,10,12]
#PF-Assgn-24
def form_triangle(num1,num2,num3):
success="Triangle can be formed"
failure="Triangle can't be formed"
#Write your logic here
num = (num1,num2,num3)
highest_value = num.index(max(num))
addition_smaller_sides = 0
for index in range(3):
if index == highest_value:
continue
addition_smaller_sides += num[index]
if highest_value < addition_smaller_sides:
return success
else:
return failure
#Use the following messages to return the result wherever necessary
#Provide different values for the variables, num1, num2, num3 and test your program
num1=3
num2=3
num3=5
form_triangle(num1, num2, num3)
# PF-Tryout
#Provide different values for heads and legs and test your program
solve(38,131)
'''
alex.color("black") # alex has a color
alex.right(60) # alex turns 60 degrees right
alex.left(60) # alex turns 60 degrees left
alex.circle(50) # draws a circle of radius 50
#draws circles
for counter in range(1,3):
alex.circle(20*counter)
'''
#PF-Assgn-28
def encode(message):
arange = [1, message[0]]
encode = ""
status=check_palindrome("malayalam")
if(status):
print("word is palindrome")
else:
print("word is not palindrome")
#PF-Assgn-32
def max_visited_speciality(patient_medical_speciality_list,medical_speciality):
# write your logic here
count_medical_speciality = {}
for key in medical_speciality:
count_medical_speciality[key] = 0
for med_speciality in patient_medical_speciality_list[1::2]:
count_medical_speciality[med_speciality] += 1
max_speciality = max(count_medical_speciality, key=count_medical_speciality.get)
return medical_speciality[max_speciality]
msg2 = set(msg2)
#Remove pass and write your logic here
common_characters = ""
for char in filtered_msg1:
if char == " ":
continue
elif char in filtered_msg2:
common_characters += char
if len(common_characters) > 0:
return common_characters
else:
return -1
#PF-Assgn-34
def find_pairs_of_numbers(num_list,n):
#Remove pass and write your logic here
pairs = 0
for i in range(len(num_list) - 1):
for j in range(i, len(num_list)):
if num_list[i] + num_list[j] == n:
pairs += 1
return pairs
num_list=[1, 2, 4, 5, 6]
n=6
print(find_pairs_of_numbers(num_list,n))
#PF-Assgn-35
#Global variable
list_of_marks=(12,18,25,24,2,5,18,20,20,21)
def find_more_than_average():
#Remove pass and write your logic here
above_average = 0
average_marks = sum(list_of_marks)/len(list_of_marks)
for i in map(lambda x : x > average_marks, list_of_marks):
if i == True:
above_average += 1
return above_average/len(list_of_marks)*100
def sort_marks():
#Remove pass and write your logic here
return sorted(list_of_marks)
def generate_frequency():
#Remove pass and write your logic here
frequency = [0]*26
for marks in list_of_marks:
frequency[marks] += 1
return frequency
print(find_more_than_average())
print(generate_frequency())
print(sort_marks())
#PF-Assgn-36
def create_largest_number(number_list):
#remove pass and write your logic here
largest_number = ""
for num in sorted(number_list,reverse=True):
largest_number += str(num)
return int(largest_number)
number_list=[23,45,67]
largest_number=create_largest_number(number_list)
print(largest_number)
#PF-Assgn-37
#Global variables
child_id=(10,20,30,40,50)
chocolates_received=[12,5,3,4,6]
def calculate_total_chocolates():
#Remove pass and write your logic here to find and return the total number of chocolates
return sum(chocolates_received)
def reward_child(child_id_rewarded,extra_chocolates):
#Remove pass and write your logic here
if extra_chocolates < 1:
print("Extra chocolates is less than 1")
elif not(child_id_rewarded in child_id):
print("Child id is invalid")
else:
chocolates_received[child_id.index(child_id_rewarded)] += extra_chocolates
print(chocolates_received)
print(calculate_total_chocolates())
#Test your code by passing different values for child_id_rewarded,extra_chocolates
reward_child(20,2)
#PF-Assgn-38
def check_double(number):
if number == 0:
return False
double = str(number * 2)
number = str(number)
if len(number) == len(double):
double_char_list = []
for char in double:
double_char_list.append(char)
for char in number:
if char in double_char_list:
double_char_list.remove(char)
else:
return False
else:
return False
return True
#Remove pass and write your logic here
#Global variables
menu=('Veg Roll','Noodles','Fried Rice','Soup')
quantity_available=[2,200,3,0]
'''This method accepts the item followed by the quantity required by a customer in the format item1, quantity_required, item2,
quantity_required etc.'''
def place_order(*item_tuple):
#Remove pass and write your logic here
if not(item_tuple[order] in menu):
print(item_tuple[order], "is not available")
else:
print(item_tuple[order], "stock is over")
'''This method accepts the index position of the item requested by the customer in the quantity_available list, and the
requested quantity of the item.'''
def check_quantity_available(index,quantity_requested):
#Remove pass and write your logic here to return an appropriate boolean value.
if quantity_available[index] < quantity_requested:
return False
else:
quantity_available[index] -= quantity_requested
return True
#Provide different values for items ordered and test your program
#place_order("Veg Roll",2,"Noodles",2)
#place_order("Soup",1,"Veg Roll", 2, "Fried Rice1",1)
place_order("Fried Rice",2,"Soup",1)