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 / s14q03_solution.py
Created November 20, 2018 21:41
Entering 10 numbers, taking 5 random numbers and printing random numbers in order of input.
''' Entering 10 numbers, taking 5 random numbers and printing random numbers in order of input '''
import random
def enter_number():
return int(input("Enter number: "))
def list_of_numbers():
number_list = list()
for num in range(1, 11):
number = enter_number()
@Ojha-Shashikant
Ojha-Shashikant / s14q02_solution.py
Created November 20, 2018 21:03
Create a file with student details, read from file and write student details in ascending order of marks greater than 90%.
''' create a file with student details, read from file and write student details in ascending order of marks greater than 90% '''
import s14q01_solution
def creating_file():
FH = open("C:\\Users\\Ojha\\Documents\\Python exercises\\Python Scripts\\student.txt", "w+")
print("File student.txt created")
return FH
def writing_on_file(FH):
@Ojha-Shashikant
Ojha-Shashikant / s14q01_solution.py
Created November 20, 2018 20:10
Student name and % marks scored as input and printing student details having % greater than 90% in ascending order.
''' Taking student name and % marks scored and printing student details having % greater than 90% in ascending order '''
def input_name():
return input("Enter student name: ")
def input_marks():
return float(input("Enter student % marks scored: "))
def student_list():
name = input_name()
student_name_list = list()
@Ojha-Shashikant
Ojha-Shashikant / s13q02_solution.py
Created November 20, 2018 12:32
Finding 3 digit prime number after writing on file.
''' Finding 3 digit prime number after writing on file. '''
import s13q01_solution
def create_file():
FH = open("C:\\Users\\Ojha\\Documents\\Python exercises\\Python Scripts\\num.txt", "w+")
return FH
def writing_to_file(FH):
number_of_lines = int(input("How many numbers you want to write into the file? "))
@Ojha-Shashikant
Ojha-Shashikant / s13q01_solution.py
Created November 20, 2018 10:42
3 digit prime numbers in decending order, number input by user
''' 3 digit prime numbers in decending order, number input by user '''
def input_3_digit_num():
return int(input("Please enter 3 digit number: "))
def numbers_entered_list(num):
number_list = list()
while num != 0:
if num != 0 and 100 <= num <= 999:
number_list.append(num)
@Ojha-Shashikant
Ojha-Shashikant / s0Cq03_solution.py
Created November 15, 2018 18:58
Inserts some text in any given line of a file.
#!/usr/bin/python
"""
This program insert's some text in any given line of a file.
Input :
Filename is taken as argument to the program
The user is prompted for the line where the text
is to be inserted
Output :
The same file is updated with some new text
"""
@Ojha-Shashikant
Ojha-Shashikant / s0Cq02_solution.py
Last active November 14, 2018 00:54
Reads a file as input using fileops.py and print a random line from it
'''Reads a file as input using fileops.py and print a random line from it'''
import random
from s0Cq01_fileops import get_lines
import sys
# Get filename from command line
def reading_CLI():
file_name = sys.argv[1]
file_complete_path = "C:\\Users\\Ojha\\Documents\\Python exercises\\Python Scripts\\" + file_name
@Ojha-Shashikant
Ojha-Shashikant / s0Cq01_shuffle_lines.py
Created November 13, 2018 18:26
Taking lines from a line and creating a new file with shuffled lines.
""" Takes a filename as argument
Creates a new file with the name
"shuffle" appended to the original filename.
The lines in the input are shuffled
and written into the new file
"""
import sys
#from s0Cq01_fileops import *
import s0Cq01_fileops
import random
@Ojha-Shashikant
Ojha-Shashikant / s0Cq01_fileops.py
Created November 13, 2018 18:22
Reading content from file and writing content to the file.
import sys
def get_lines(filepath):
""" Reads the contents of filename
and returns the - File handle
- List of all lines of the file
"""
FH = open(filepath, "r+")
lines = FH.readlines()
return FH, lines
''' Jackpot.py '''
import s0Bq03_sumops
import random
'''
# function to input a 5 digit number
def input_number():
num = int(input("Provide a 5 digit number: "))
return num
'''