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
''' 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() |
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
''' 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): |
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 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() |
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
''' 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? ")) |
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
''' 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) |
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
#!/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 | |
""" |
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
'''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 |
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
""" 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 |
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
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 |
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
''' 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 | |
''' |