1. Write a function to keep asking the user for names in the form of strings, sort alphabetically and store these names into a text file named names.txt
2.
Write a function that accepts a string as the argument, removes all alphabetical letters from the string, and returns it
3. Write a function that accepts a file name in the form of a string as the argument. Assume the text file contains single-digit numbers and letters. Read the entire contents of the text file and return two strings, one with numbers only, the another one with letters only
python
1. CODE
def func():
file1 = open("names.txt","w")
#list to store the names
l = []
run = True
while(run):
#input of names
temp = input("Enter
name:(-1 to stop entering) ")
if(temp == '-1'):
run = False
else:
l.append(temp)
#sorting list
l.sort()
for name in l:
file1.write(name+"\n")
file1.close()
func()
SCREENSHOT 1:

OUTPUT 1:

FILE

CODE 2:
def func(s):
t = ""
#iterating each character
for i in s:
#store if not
alphabet
if (i < 'A' or i > 'Z')
and (i < 'a' or i > 'z'):
t +=
i
#printing string
print(t)
#input of string
s = input()
func(s)
OUTPUT 2:

SCREENSHOT 2:

CODE 3:
def func(fileName):
#opening file
file = open(fileName,"r")
#reading file
s = file.read()
#spliting text by spaces in characters
chars = s.split(' ')
digits = []
alpha = []
#iterating each chars
for char in chars:
#if char is digit
if char>='0' and
char<='9':
digits.append(char)
#if char is
alphabet
elif (char>='a' and
char<='z') or (char>='A' and char<='Z'):
alpha.append(char)
print(digits)
print(alpha)
#input of file name
fileName = input()
func(fileName)
SCREENSHOT 3:

OUTPUT3 :

File:

1 filel = open("names.txt", "w") #input pf no. of inputs n = int(input) 6 7 #List to store the names 1 = 1 9 #input of names 10 for i in range(n): temp = input() 1.append(temp) 12 14 #sorting List 15 1.sort) 17 #writing in a file 18 for name in 1: 19 file1.write(name+"\n") 21 filel.close()
anubhav subro pratik sachin -- Program finished with exit code o Press ENTER to exit console.
anubhav pratik sachin subro
aln2u3b4h5a6v7 1234567 - - Program finished with exit code 0 Press ENTER to exit console.]
i 2 3 #input of string 5 = input() t = "" #iterating each character 6. for i in s: #store if not alphabet if (i < 'A' or i > 'Z') and (i < 'a' or i> 'Z'); t te i 11 #printing string 12 print(t) 14
1 #input of file name 2 fileName = input() 4 #opening file file = open(fileName, "r") 8 #reading file 5 = file.read() 10 #spliting text by spaces in characters 11 chars = s.split(' ') 12 digits = [] 13 alpha = [] 14 15 #iterating each chars 16" for char in chars: 17 #if char is digit 18 - if char>='0' and char<='9': digits.append(char) #if char is alphabet elif (char>='a' and char<='z') or (char>='A' and char<='Z'); alpha.append(char) 24 print(digits) print(alpha)
names.txt ['1', '2', '3', '4', '5', '6', '7'] ['a', 'n', 'u', 'b', 'h', 'a', 'v'] -- Program finished with exit code o Press ENTER to exit console-
1 a 1 n 2 u 3 b 4 h 5 a 6 v 7
1. Write a function to keep asking the user for names in the form of strings,...
In python,write a function nameSet(first, last) that takes a person's first and last names as input, and returns a tuple of three strings: the first string gives the union of all letters in the first and last names (no duplication though). The second string gives the intersection of letters in the first and last names, i.e. the common letters. If there are no common letters, then the second string is empty (''). The third string gives the symmetric difference between...
1.) Write a recursive function named isPalindrome that will take a single string as an argument and determine if the argument is a palindrome. The function must return True if the argument is a palindrome, False otherwise. Recall that any string is a palindrome if its first and last characters are the same and the rest of it is also a palindrome (therefore, a single character is a palindrome): 2.) Consider a text file named samplestrings.txt that contains a collection...
in c++
Program 1 Write a program that sorts a vector of names alphabetically using the selection sort and then searches the vector for a specific name using binary search. To do that, you need to write three functions I. void selSort (vector string &v: sorts the vector using selection sort 2. void display (const vector <string & v): displays the vector contents . int binSearch (const vector <ing& v, string key): searches the vector for a key returns the...
Write a function named words_in_both that takes two strings as parameters and returns a set of the words contained in both strings. You can assume all characters are letters or spaces. Capitalization shouldn't matter: "to", "To", "tO", and "TO" should all count as the same word. The words in the set should be all lower-case. For example, if one string contains "To", and the other string contains "TO", then the set should contain "to". The file must be named: words_in_both.py...
PYTHON 3.6.1 write a script named copyfile.py. this script should prompt the user for the names of two text files. the contents of the first file should be input and written to the second file.
1. Write a program to input a list of names (strings) from the user and store them in an ArrayList. The input can be terminated by entering the empty string or by entering the string “quit”. 2. Add further functionality to your program so that it searches the ArrayList to find the first string and the last string according to dictionary ordering and then prints out these strings (names). Do this exercise without sorting the names in the ArrayList. For...
Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. Note: The sort function sorts first numbers, then capital letters, then lowercase letters. That is fine for this assignment as you can see from the sample output. But even if the same word appears multiple times in the file it should only be displayed once in the output. (python)
python: Write a function named "write_values" that takes a key-value store mapping strings to strings as a parameter and writes the values of the input to a file named "persuade.txt" with one element per line. If a file named "persuade.txt" already exists it must be overwritten. The function should not return any value
Java console-based question. Do not use BufferedReader please. A file named customers.txt contains the names of customers for a local hairdressing salon. Unfortunately, the data in the file is in no particular order yet the owner of the salon would like the data in alphabetical order. Write a Java program that reads the contents of the file into an array of Strings, sorts the array of Strings into alphabetical order, and then writes the content of the array to a...
Write a function called most_consonants(words) that takes a list of strings called words and returns the string in the list with the most consonants (i.e., the most letters that are not vowels). You may assume that the strings only contain lowercase letters. For example: >>> most_consonants(['python', 'is', 'such', 'fun']) result: 'python' >>> most_consonants(['oooooooh', 'i', 'see', 'now']) result: 'now' The function that you write must use a helper function (either the num_vowels function from lecture, or a similar function that you...