Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 29

PF DAY 1:

#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

#Start writing your code from here


#Populate the variables: per_head_cost and divisible_by_five
total_distance=distance_one_way*2
petrol = (total_distance/mileage)*amount_per_litre
per_head_cost = petrol/4
if per_head_cost%5==0:
divisible_by_five=True
#Do not modify the below print statements for verification to work
print(per_head_cost)
print(divisible_by_five)

#PF-Assgn-4
#This verification is based on string match.
#Day 1
principal=7800
rate_of_interest=7.7
time=26
interest=0

#Start writing your code from here


#Populate the variable: interest
interest=(principal * rate_of_interest * time) / 100

#Do not modify the below print statement for verification to work
print(interest)
#PF-Assgn-22
def find_leap_years(given_year):

# Write your logic here


list_of_leap_years = []
while(len(list_of_leap_years) < 15):
if(given_year%4==0):
if(given_year%100==0):
if(given_year%400==0):
list_of_leap_years.append(given_year)
else:
list_of_leap_years.append(given_year)
given_year += 1
return list_of_leap_years

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

#List of gems available in the store


gems_list=["Emerald","Ivory","Jasper","Ruby","Garnet"]

#Price of gems available in the store. gems_list and price_list have one-to-one correspondence
price_list=[1760,2119,1599,3920,3999]

#List of gems required by the customer


reqd_gems=["Ivory","Emerald","Garnet"]

#Quantity of gems required by the customer. reqd_gems and reqd_quantity have one-to-one
correspondence
reqd_quantity=[3,10,12]

bill_amount=calculate_bill_amount(gems_list, price_list, reqd_gems, reqd_quantity)


print(bill_amount)

#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

# debug the below code


counter1 = 0
counter2 = 5
while(counter1 < 5):
star = ""
while(counter2 > counter1):
star = star + "*"
counter2 -= 1
print(star)
counter1 += 1
counter2 = 5
#PF-Assgn-26
def solve(heads,legs):
#Start writing your code here
#Populate the variables: chicken_count and rabbit_count
error_msg="No solution"
chicken_count=0
rabbit_count=0

rabbit_count = legs/2 - heads


chicken_count = heads - rabbit_count

check_rabbit = int(rabbit_count) == rabbit_count and rabbit_count >= 0


check_chicken = int(chicken_count) == chicken_count and chicken_count >= 0

if check_rabbit and check_chicken:


print(int(chicken_count), int(rabbit_count))
else:
print(error_msg)

# Use the below given print statements to display the output


# Also, do not modify them for verification to work
#print(chicken_count,rabbit_count)
#print(error_msg)

#Provide different values for heads and legs and test your program
solve(38,131)

import turtle # allows us to use the turtles library


wn = turtle.Screen() # creates a graphics window
wn.setup(500,500) # set window dimension

alex = turtle.Turtle() # create a turtle named alex


alex.shape("turtle") # alex looks like a turtle
alex.color("red")
for counter in range(2,6):
alex.circle(20*counter)
alex.right(-120)
alex.color("green")
for counter in range(2,6):
alex.circle(20*counter)
alex.right(-120)
alex.color("blue")
for counter in range(2,6):
alex.circle(20*counter)

'''
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)
'''

#Write the logic to create the given pattern


#Refer the statements given above to draw the pattern

#PF-Assgn-28

def find_max(num1, num2):


if num2 < num1:
return -1
for num in range(num2, num1, -1):
if len(str(num)) == 2:
if num % 5 == 0:
if ((num // 10) + (num % 10)) % 3 == 0:
return num
return -1
#Provide different values for num1 and num2 and test your program.
max_num=find_max(10,15)
print(max_num)
#PF-Assgn-29
def calculate(distance,no_of_passengers):
price_per_liter=70
milege_per_liter=10
ticket_price=80
expenditure=(distance/milege_per_liter)*price_per_liter
income=no_of_passengers*ticket_price
if income >= expenditure:
return income-expenditure
else:
return -1
#Provide different values for distance, no_of_passenger and test your program
distance=20
no_of_passengers=50
print(calculate(distance,no_of_passengers))
#PF-Assgn-30

def encode(message):
arange = [1, message[0]]
encode = ""

for char in message[1:]:


if char == arange[-1]:
arange[-2] = 1 + arange[-2]
else:
arange.extend([1, char])

for item in arange:


encode += str(item)
return encode
#Remove pass and write your logic here

#Provide different values for message and test your program


encoded_message=encode("ABBBBCCCCCCCCAB")
print(encoded_message)
#PF-Assgn-31
def check_palindrome(word):
if word==word[::-1]:
return True
else:
return False
#Remove pass and write your logic here

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]

#provide different values in the list and test your program


patient_medical_speciality_list=[301,'P',302, 'P' ,305, 'P' ,401, 'E' ,656, 'E']
medical_speciality={"P":"Pediatrics","O":"Orthopedics","E":"ENT"}
speciality=max_visited_speciality(patient_medical_speciality_list,medical_speciality)
print(speciality)
#PF-Assgn-33
def find_common_characters(msg1,msg2):
filtered_msg1 = []
filtered_msg2 = []

for char in msg1:


if not char in filtered_msg1:
filtered_msg1.append(char)

for char in msg2:


if not char in filtered_msg2:
filtered_msg2.append(char)

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

#Provide different values for msg1,msg2 and test your program


msg1="I like Python"
msg2="Java is a very popular language"
common_characters=find_common_characters(msg1,msg2)
print(common_characters)

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

# Use the below given print statements to display the output


# Also, do not modify them for verification to work

#print("Extra chocolates is less than 1")


#print("Child id is invalid")
#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

#Provide different values for number and test your program


print(check_double(125874))
#PF-Assgn-39
#This verification is based on string match.

#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

for order in range(0,len(item_tuple),2):

if not(item_tuple[order] in menu):
print(item_tuple[order], "is not available")

elif check_quantity_available(menu.index(item_tuple[order]), item_tuple[order + 1]):


print (item_tuple[order], "is available")

else:
print(item_tuple[order], "stock is over")

#Populate the item name in the below given print statements


#Use it to display the output wherever applicable
#Also, do not modify the text in it for verification to work

#print("<item name>is not available")


#print("<item name>stock is over")
#print ("<item name>is available")

'''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)

You might also like