This file contains 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 test_suite(test_inputs): | |
for tst, exp in test_inputs.items(): | |
actual = check_palindrome(tst) | |
if actual == exp: | |
print("OK") | |
else: | |
print("NOK") | |
def check_palindrome(string): | |
""" |
This file contains 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 the number of innings Sachin scored less than 25 runs in 2001 | |
import sys | |
import os | |
from math import sum | |
# Fill the missing pieces in the below line to get the list of runs scored by Sachin in 2001. | |
# runs = [ num.strip() for num in open("sachin_runs.csv").read().split() ] | |
# Use the above "runs" list to find out the number of innings Sachin scored less than 25 runs | |
## YOUR CODE GOES HERE ## | |
''' |
This file contains 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 program to print the first 12 "even" Fibonacci numbers ''' | |
def calculate_fibo(): | |
previous_value = 1 | |
current_value = 1 | |
series = [1,1] | |
for i in range(1, 1000): | |
new_value = current_value + previous_value | |
series.append(new_value) | |
previous_value = current_value |
This file contains 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
''' Searching from phonebook, based on string input search ''' | |
def file_input(): | |
filename = input("Please enter filename: ") | |
return filename | |
def input_string(): | |
char_input = input("Please enter string you are searching for: ") | |
return char_input.lower() |
This file contains 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
''' Reading password file, printing output in ascending order of user id with user real name and home directory ''' | |
def reading_file(): | |
with open("C:\\Users\\Ojha\\Documents\\Python exercises\\Python Scripts\\password.txt", 'r+') as FH: | |
text = FH.read() | |
return text | |
def file_data_operation(text): | |
lines = text.split('\n') | |
users_data = dict() |
This file contains 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
''' Reading words and printing top 10 most occurring words in descending order also list of non-repeated words''' | |
import re | |
def file(): | |
file_path = "C:\\Users\\Ojha\\Documents\\Python exercises\\Python Scripts\\" | |
file_name = "Paragraph.txt" | |
return file_path, file_name | |
def reading_file(file_path, file_name): |
This file contains 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
''' Read the file Age.txt and print the names in descending order of Age ''' | |
def reading_file(): | |
FH = open("C:\\Users\\Ojha\\Documents\\Python exercises\\Python Scripts\\Age.txt", 'r+') | |
return FH | |
def file_operation(FH): | |
text = FH.read() | |
FH.close() | |
new_text = text.split() |
This file contains 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
''' Writing contacts to file, reading contacts from file and printing in ascending order of names ''' | |
def creating_file(): | |
FH = open("C:\\Users\\Ojha\\Documents\\Python exercises\\Python Scripts\\Contact_list.txt", 'w') | |
return FH | |
def name_input(): | |
name = input("Provide contact person name: ") | |
final_name = name.capitalize() | |
return final_name |
This file contains 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
''' Taking 2 sorted lists as argument, combine both the lists and print the sorted final list ''' | |
def input_number(): | |
return input("Please enter numbers for your list: ") | |
def input_list(): | |
num = input_number() | |
list_input = list() | |
while num!= '': | |
list_input.append(int(num)) |
This file contains 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
''' 10 friends picking numbers between 99 and 999, display the winner with maximum picked number ''' | |
import random | |
def picking_card(): | |
pick = random.randint(100,998) | |
return pick | |
def friends_pick(): | |
friends_card_list = list() |
NewerOlder