python code:
TASK1:
if __name__ == "__main__":
#input file name from user
fname=raw_input("Enter name of the postcode file: ")
#open file
file=open(fname)
#to store the post codes
code=[]
#to store the suburbs
sub=[]
for line in file:
#first split line using '\t'
l1=line.split("\t")
#next split using ','
for suburb in l1[1].split(','):
#remove '\n' in last term
if(suburb[-1]=='\n'):
suburb=suburb[:-1]
print l1[0],suburb
CODE IMAGE:
OUTPUT:
TASK2:
#binart search using recursion
def binary_search(srt, f, l, key):
#if front more than last then not found
if not f < l:
return -1
#calculate mid
mid = (f + l)//2
#compate key with arrays mid index element
if srt[mid] < key:
return binary_search(srt, mid + 1, l, key)
elif srt[mid] > key:
return binary_search(srt, f, mid, key)
else:
return mid
#return index position
def selection(srt):
for i in range(len(srt)):
min_idx = i
for j in range(i+1, len(srt)):
if srt[min_idx] > srt[j]:
min_idx = j
srt[i], srt[min_idx] = srt[min_idx], srt[i]
return srt
if __name__ == "__main__":
#input file name from user
fname=raw_input("Enter name of the postcode file: ")
#open file
file=open(fname)
#to store the post codes
code=[]
#to store the suburbs
sub=[]
for line in file:
#first split line using '\t'
l1=line.split("\t")
#next split using ','
for suburb in l1[1].split(','):
#remove '\n' in last term
if(suburb[-1]=='\n'):
suburb=suburb[:-1]
#print l1[0],suburb
code.append(l1[0])
sub.append(suburb)
#copy suburbs to srt to sort further
srt=sub[:]
#sort the array
srt=selection(srt)
#get suburb fromuser
suburb=raw_input("Enter Suburb Name: ")
#search suburb in list
res=binary_search(srt, 0, len(srt), suburb)
if(res==-1):
print "Not Found"
else:
print "Post code is "+code[sub.index(suburb)]
CODE IMAGES:
OUTPUT:
Task 1: Write a Python program that takes as input from the user the name of a file containing po...
Write a PYTHON program that reads a file (prompt user for the input file name) containing two columns of floating-point numbers (Use split). Print the average of each column. Use the following data forthe input file: 1 0.5 2 0.5 3 0.5 4 0.5 The output should be: The averages are 2.50 and 0.5. a) Your code with comments b) A screenshot of the execution Version 3.7.2
C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...
Write a PYTHON program that asks the user for the name of the file. The program should write the contents of this input file to an output file. In the output file, each line should be preceded with a line number followed by a colon. The output file will have the same name as the input filename, preceded by “ln” (for linenumbers). Be sure to use Try/except to catch all exceptions. For example, when prompted, if the user specifies “sampleprogram.py”...
Please write this in C. Write this code in Visual Studio and upload your Source.cpp file for checking (1) Write a program to prompt the user for an output file name and 2 input file names. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs opening any of the 3 For example, (user input shown in caps in first line) Enter first...
1. Write a program called Numbers that a. prompts the user for a file name. b. reads that file assuming that its contents consist entirely of integers. c. prints the maximum, minimum, sum, count (number of integers in the file), and average of the numbers. For example, if the file numberinput.dat has the following content: 4 -2 18 15 31 27 Your program should produce the following output: csc% java Numbers Enter file name: numberinput.daft Maximum31 Minimum- -2 Sum -...
JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...
Task 1: Calling a Function PROGRAM IS IN PYTHON) SHOW INPUT AND OUTPUT SCREEN SHOTS Task 1: Calling a Function Defining a function gives it a name, specifies the parameters that are to be included in the function and structures the blocks of code. Once the basic structure of a function is finalized, you can execute it by calling it from another function or directly from the Python prompt. Following is an example to call the printme() function #!/usr/bin/python 3...
Write a complete Python program with prompts for the user for the main text file (checks that it exists, and if not, output an error message and stop), for any possible flags (including none), and for any other input that this program may need from the user: split has an option of naming the smaller files head_tail list the first 10 lines (default) and the last 10 lines (default) in order of the given text file flag: -# output #...
IN PYTHON, Write a program that reads a string from the user containing a date in the form mm/dd/ yyyy. It should print the date in the form April 12, 2017. Hint: Get the "mm" from the user entered date "mm/dd/yyyy", then convert the "mm" into a month number. You may use an list month_list = ['January', 'February','March','April', 'May','June', 'July','August', 'September', 'October', 'November', 'December']. Use the month number you got from "mm" to get the month name.
3. Write Python statements that will do the following: a) Input a string from the user. *** Print meaningful messages along with your output.* b) Print the length of the String. Example input: The sky is blue. Correct output: The length of the string is 16 Incorrect output: 16 c) Print the first character of the string. d) Print the last character of the string. 4. Save the program. Double-check the left edge for syntax errors or warning symbols before...