This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Represent a small bilingual (English-Swedish) glossary given below as a Python dictionary | |
# {"merry":"god", "christmas":"jul", "and":"och", "happy":"gott", "new":"nytt", "year":"ar"} | |
# and use it to translate your Christmas wishes from English into Swedish. | |
# That is, write a python function translate() that accepts the bilingual dictionary and a list of English words (your Christmas wish) and returns a list of equivalent Swedish words. | |
def translate(bilingual_dict,english_words_list): | |
swedish_words_list = [] | |
for x in english_words_list: | |
swedish_words_list.append(bilingual_dict[x]) | |
return swedish_words_list |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def temprature(temp): | |
celsius = (temp - 32)*(5/9) | |
return(celsius) | |
print(temprature(10)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Write a Python function to find all the Strong numbers in a given list of numbers. | |
def factorial(number): | |
if number == 1: | |
return (number) | |
elif number == 0: | |
return 1 | |
else: | |
return (number * factorial(number-1)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#count who wins | |
#This method accepts the name of winner of each match of the day | |
def find_winner_of_the_day(*match_tuple): | |
count_A = match_tuple.count("Team1") | |
count_B = match_tuple.count("Team2") | |
if count_A>count_B: | |
return("Team1") | |
elif count_A < count_B: | |
return ("Team2") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Write a python function, which accepts a list of positive integers with no repetitions and returns count of pairs of numbers in the list that adds up to n. The function should return 0, if no such pairs are found in the list. | |
def find_pairs_of_numbers(num_list,n): | |
count = 0 | |
for num1 in num_list: | |
for num2 in num_list: | |
if (num1 + num2) == n: | |
count = count + 1 | |
return int(count/2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A teacher is in the process of generating few reports based on the marks scored by the students of her class in a project based assessment. | |
# Assume that the marks of her 10 students are available in a tuple. The marks are out of 25. | |
# Write a python program to implement the following functions: | |
# 1. find_more_than_average(): Find and return the percentage of students who have scored more than the average mark of the class. | |
# 2. generate_frequency(): Find how many students have scored the same marks. For example, how many have scored 0, how many have scored 1, how many have scored 3….how many have scored 25. The result should be populated in a list and returned. | |
# 3. sort_marks(): Sort the marks in the increasing order from 0 to 25. The sorted values should be populated in a list and returned. | |
#Global variable | |
list_of_marks=(12,18,25,24,2,5,18,20,20,21) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#A python function 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. | |
def create_largest_number(number_list): | |
number_list.sort() | |
res = "" | |
for num in number_list: | |
res = str(num) + res | |
return (int(res)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A teacher is conducting a camp for a group of five children. Based on their performance and behavior during the camp, the teacher rewards them with chocolates. | |
# Write a Python function to | |
# 1.Find the total number of chocolates received by all the children put together. | |
# Assume that each child is identified by an id and it is stored in a tuple and the number of chocolates given to each child is stored in a list. | |
# 2. The teacher also rewards a child with few extra chocolates for his/her best conduct during the camp. | |
# a. If the number of extra chocolates is less than 1, an error message "Extra chocolates is less than 1", should be displayed. | |
# b. If the given child Id is invalid, an error message "Child id is invalid" should be displayed. Otherwise, the extra chocolates provided for the child must be added to his/her existing number of chocolates and display the list containing the total number of chocolates received by each child. | |
child_id=(10,20,30,40,50) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write a python function, check_double(number) which accepts a whole number and returns True if it satisfies the given conditions. | |
# 1. The number and its double should have exactly the same number of digits. | |
# 2. Both the numbers should have the same digits ,but in different order. | |
# Otherwise it should return False. | |
# convert number to list | |
#O(n) | |
def numToList(number): | |
l_st = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''A vendor at a food court is in the process of automating his order management system. | |
The vendor serves the following menu – Veg Roll, Noodles, Fried Rice and Soup and also maintains the quantity available for each item. The customer can order any combination of items. The customer is provided the item if the requested quantity of item is available with the vendor. | |
Write a python program which implements the following functions. | |
place_order(*item_tuple): This function accepts the order placed by the customer. Consider it to be a variable length argument as each customer may have a different order. | |
The function should check whether the items requested are present in the vendor’s menu and if so, it should check whether the requested quantity is available for each by invoking the check_quantity_available() method. | |
The function should display appropriate messages for each item in the order for the below scenarios: |