Skip to content

Instantly share code, notes, and snippets.

View Ojha-Shashikant's full-sized avatar

Ojha-Shashikant

View GitHub Profile
@Ojha-Shashikant
Ojha-Shashikant / code_challenge_q31.py
Created January 30, 2019 15:13
To check Palindrome status.
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):
"""
@Ojha-Shashikant
Ojha-Shashikant / code_challenge_q21.py
Created January 30, 2019 14:58
Sachin runs in 2001.
# 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 ##
'''
@Ojha-Shashikant
Ojha-Shashikant / code_challenge_q11.py
Created January 30, 2019 14:13
Program to print the first 12 "even" Fibonacci numbers
''' 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
@Ojha-Shashikant
Ojha-Shashikant / s17q03_solution.py
Created November 30, 2018 14:39
Searching from phonebook, based on string input search.
''' 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()
@Ojha-Shashikant
Ojha-Shashikant / s17q02_solution.py
Created November 30, 2018 14:38
Reading password file, printing output in ascending order of user id with user real name and home directory.
''' 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()
@Ojha-Shashikant
Ojha-Shashikant / s17q01_solution.py
Created November 30, 2018 14:36
Reading words and printing top 10 most occurring words in descending order also list of non-repeated words.
''' 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):
@Ojha-Shashikant
Ojha-Shashikant / s16q02_solution.py
Last active November 29, 2018 09:14
Read the file Age.txt and print the names in descending order of Age.
''' 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()
@Ojha-Shashikant
Ojha-Shashikant / s16q01_solution.py
Created November 25, 2018 21:13
Writing contacts to file, reading contacts from file and printing in ascending order of names.
''' 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
@Ojha-Shashikant
Ojha-Shashikant / s15q02_solution.py
Created November 24, 2018 17:37
Taking 2 sorted lists as argument, combine both the lists and print the sorted final list.
''' 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))
@Ojha-Shashikant
Ojha-Shashikant / s15q01_solution.py
Created November 21, 2018 21:11
10 friends picking numbers between 99 and 999, display the winner with maximum picked number.
''' 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()