below is my code please help me edit it so in the beginning it ask for Press any key to start Task n, where n is the task number (1, 2, or 3,4). I already wrote the code for the 4 task. Also please write it so when 1 code is finish running it return to the prompt where it ask to run another task
#task 1
list1 =
['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','.',',','?']
morse =
['.-','-...','-.-.','-..','.','..-.','--.','....','..','.---','-.-','.-..','--','-.','---','.--.','--.-','.-.','...','-','..-','...-','.--','-..-','-.--','--..','-----','.----','..---','...--','....-','.....','-....','--...','---..','----.','.-.-.-','--..--','..--..']
inp = input("Enter original text : ")
inp = inp.lower()
for i in inp:
if i == ' ':
print(end=" ")
if i in list1:
print(morse[list1.index(i)], end= "")
print()
#task 2
def calcPercentage(quiz, assignment, midTerm, final):
""" Function that calculates percentage """
# Sorting quiz scores
quiz.sort();
# Sorting assignment scores
assignment.sort();
# Calculating final percentage
per = ( ( sum(quiz[2:])/4.0 ) * 0.25 ) + ( (
sum(assignment[1:])/3.0 ) * 0.25 ) + (midTerm * 0.25) + (final *
0.25);
return per;
def main():
""" Main function """
# Lists for holding values
names = [];
quiz = [];
assignment = [];
midTerm = [];
final = [];
grade = [];
percentage = [];
# Opening file in reading
with open("d:\Python\stuGrade.txt") as fp:
# Iterating over each line
for line in fp:
# Splitting on comma
cols = line.strip().split(',');
names.append(cols[0]);
qTemp = [];
qTemp.append(int(cols[1]));
qTemp.append(int(cols[2]));
qTemp.append(int(cols[3]));
qTemp.append(int(cols[4]));
qTemp.append(int(cols[5]));
qTemp.append(int(cols[6]));
# Adding to quiz list
quiz.append(qTemp);
# Working with Assignment
aTemp = [];
aTemp.append(int(cols[7]));
aTemp.append(int(cols[8]));
aTemp.append(int(cols[9]));
aTemp.append(int(cols[10]));
# Adding to list
assignment.append(aTemp);
# Adding to Mid term
midTerm.append(int(cols[11]));
# Adding to Final
final.append(int(cols[12]));
# Iterating over each list and finding grade and percentage
for i in range(0, len(names)):
# finding percentage
per = calcPercentage(quiz[i][:], assignment[i][:], midTerm[i],
final[i]);
# Adding percentage
percentage.append(per);
# Finding Grade(pass/fail)
if per >= 60:
grade.append("pass");
else:
grade.append("fail");
print("\n \t\t\t\t\t GRADE RESULT ");
# Printing report
print("\n\n %-6s %-6s %-6s %-6s %-6s %-6s %-6s %-6s %-6s %-6s %-6s
%-6s %-6s %-6s \n" %("Name", "Quiz1", "Quiz2", "Quiz3", "Quiz4",
"Quiz5", "Quiz6", "Asgn1", "Asgn2", "Asgn3", "Asgn4", "MidT",
"Final", "Result"));
# Iterating over each list and finding grade and percentage
for i in range(0, len(names)):
# Printing each student info
print(" %-6s %-6d %-6d %-6d %-6d %-6d %-6d %-6d %-6d %-6d %-6d %-6d
%-6d %-4s: %4.2f " %(names[i], quiz[i][0], quiz[i][1], quiz[i][2],
quiz[i][3], quiz[i][4], quiz[i][5], assignment[i][0],
assignment[i][1], assignment[i][2], assignment[i][3], midTerm[i],
final[i], grade[i], percentage[i]));
print("\n\n");
# Calling main function
main();
#task3
def read_file(d,e):#this function used to read the file and append
its elements to the respected dictionary
for x in d:
x=x[:-1]
arr=x.split(",");#we split the each readed line based on the
comma
e[arr[0]]=arr[1]#in this we assign course number as key and other
value after comma as the value
f1=input("CourseInstructors file name:")#this line ask the file
name of the courseinstructor.
f2=input("CourseRoom file name:")#this line ask the file name of
the courseroom file name.
f3=input("CourseTimes file name:")#this line ask the file name of
the coursetimes.
#the below 3 line used to read the files.
f1=open(f1,"r");
f2=open(f2,"r")
f3=open(f3,"r")
a={};b={};c={}#these 3 dictionaries used to store the keys and
values in the txt files
#a dictionary stores the values in the courseInstructor file
#b dictionary stores the values in the courserooms file
#c dictionary stores the values in the courseTimes file
read_file(f1,a)
read_file(f2,b)
read_file(f3,c)
y=a.keys()#this line returns the all the keys in the a
dictionary
print("---------------------------------------------------------------")
print("course\t\tName\t\tRoom\t\tTime")
print("---------------------------------------------------------------")
for i in y:#this loop used to print the values of the respected
keys in the 3 dictionaries
print(i+"\t\t"+a[i]+"\t\t"+b[i]+"\t\t"+c[i])
#task 4
file1 = "one.txt"
file2 = "two.txt"
A = set(open(file1).read().split()) # READING from files and taking words into lists
B = set(open(file2).read().split())
# using set operations to find the results
print("Unique words")
print(A | B) # | is for UNION
print("\nBoth files")
print(A & B) # & is for INTERSECTION
print("\nFirst file but not in the second")
print(A-B) # - is for difference
print("\nSecond but not in the first")
print(B-A)
print("\nFirst or Second but not both")
print((A-B) | (B-A))
# task 1 list1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', ',', '?'] morse = ['.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-', '...-', '.--', '-..-', '-.--', '--..', '-----', '.----', '..---', '...--', '....-', '.....', '-....', '--...', '---..', '----.', '.-.-.-', '--..--', '..--..'] def task1(): inp = input("Enter original text : ") inp = inp.lower() for i in inp: if i == ' ': print(end=" ") if i in list1: print(morse[list1.index(i)], end="") print() def calcPercentage(quiz, assignment, midTerm, final): """ Function that calculates percentage """ # Sorting quiz scores quiz.sort() # Sorting assignment scores assignment.sort(); # Calculating final percentage per = ((sum(quiz[2:]) / 4.0) * 0.25) + ((sum(assignment[1:]) / 3.0) * 0.25) + (midTerm * 0.25) + (final * 0.25); return per; def task2(): # Lists for holding values names = []; quiz = []; assignment = []; midTerm = []; final = []; grade = []; percentage = []; # Opening file in reading with open("d:\Python\stuGrade.txt") as fp: # Iterating over each line for line in fp: # Splitting on comma cols = line.strip().split(','); names.append(cols[0]); qTemp = []; qTemp.append(int(cols[1])); qTemp.append(int(cols[2])); qTemp.append(int(cols[3])); qTemp.append(int(cols[4])); qTemp.append(int(cols[5])); qTemp.append(int(cols[6])); # Adding to quiz list quiz.append(qTemp); # Working with Assignment aTemp = []; aTemp.append(int(cols[7])); aTemp.append(int(cols[8])); aTemp.append(int(cols[9])); aTemp.append(int(cols[10])); # Adding to list assignment.append(aTemp); # Adding to Mid term midTerm.append(int(cols[11])); # Adding to Final final.append(int(cols[12])); # Iterating over each list and finding grade and percentage for i in range(0, len(names)): # finding percentage per = calcPercentage(quiz[i][:], assignment[i][:], midTerm[i], final[i]); # Adding percentage percentage.append(per); # Finding Grade(pass/fail) if per >= 60: grade.append("pass"); else: grade.append("fail"); print("\n \t\t\t\t\t GRADE RESULT "); # Printing report print("\n\n %-6s %-6s %-6s %-6s %-6s %-6s %-6s %-6s %-6s %-6s %-6s %-6s %-6s %-6s \n" % ( "Name", "Quiz1", "Quiz2", "Quiz3", "Quiz4", "Quiz5", "Quiz6", "Asgn1", "Asgn2", "Asgn3", "Asgn4", "MidT", "Final", "Result")); # Iterating over each list and finding grade and percentage for i in range(0, len(names)): # Printing each student info print(" %-6s %-6d %-6d %-6d %-6d %-6d %-6d %-6d %-6d %-6d %-6d %-6d %-6d %-4s: %4.2f " % ( names[i], quiz[i][0], quiz[i][1], quiz[i][2], quiz[i][3], quiz[i][4], quiz[i][5], assignment[i][0], assignment[i][1], assignment[i][2], assignment[i][3], midTerm[i], final[i], grade[i], percentage[i])); print("\n\n"); def read_file(d, e): # this function used to read the file and append its elements to the respected dictionary for x in d: x = x[:-1] arr = x.split(","); # we split the each readed line based on the comma e[arr[0]] = arr[1] # in this we assign course number as key and other value after comma as the value def task3(): f1 = input("CourseInstructors file name:") # this line ask the file name of the courseinstructor. f2 = input("CourseRoom file name:") # this line ask the file name of the courseroom file name. f3 = input("CourseTimes file name:") # this line ask the file name of the coursetimes. # the below 3 line used to read the files. f1 = open(f1, "r"); f2 = open(f2, "r") f3 = open(f3, "r") a = {}; b = {}; c = {} # these 3 dictionaries used to store the keys and values in the txt files # a dictionary stores the values in the courseInstructor file # b dictionary stores the values in the courserooms file # c dictionary stores the values in the courseTimes file read_file(f1, a) read_file(f2, b) read_file(f3, c) y = a.keys() # this line returns the all the keys in the a dictionary print("---------------------------------------------------------------") print("course\t\tName\t\tRoom\t\tTime") print("---------------------------------------------------------------") for i in y: # this loop used to print the values of the respected keys in the 3 dictionaries print(i + "\t\t" + a[i] + "\t\t" + b[i] + "\t\t" + c[i]) def task4(): # task 4 file1 = "one.txt" file2 = "two.txt" A = set(open(file1).read().split()) # READING from files and taking words into lists B = set(open(file2).read().split()) # using set operations to find the results print("Unique words") print(A | B) # | is for UNION print("\nBoth files") print(A & B) # & is for INTERSECTION print("\nFirst file but not in the second") print(A - B) # - is for difference print("\nSecond but not in the first") print(B - A) print("\nFirst or Second but not both") print((A - B) | (B - A)) if __name__ == '__main__': choice = 1 while choice != 0: choice = input("What is your choice? ('1' OR '2' OR '3' OR '4') :: ") if choice == '1': task1() elif choice == '2': task2() elif choice == '3': task3() elif choice == '4': task4() elif choice == '0': print("Exiting!") break else: print(choice + ' Is Not A Valid Choice')
COMMENT DOWN FOR ANY QUERIES,
AND LEAVE A THUMBS UP IF THIS ANSWER HELPS YOU.
Below is my code please help me edit it so in the beginning it ask for Press any key to start Tas...
I am having trouble with my Python code in this dictionary and pickle program. Here is my code but it is not running as i am receiving synthax error on the second line. class Student: def__init__(self,id,name,midterm,final): self.id=id self.name=name self.midterm=midterm self.final=final def calculate_grade(self): self.avg=(self.midterm+self.final)/2 if self.avg>=60 and self.avg<=80: self.g='A' elif self.avg>80 and self.avg<=100: self.g='A+' elif self.avg<60 and self.avg>=40: self.g='B' else: self.g='C' def getdata(self): return self.id,self.name.self.midterm,self.final,self.g CIT101 = {} CIT101["123"] = Student("123", "smith, john", 78, 86) CIT101["124"] = Student("124", "tom, alter", 50,...
For the following task, I have written code in C and need help in determining the cause(s) of a segmentation fault which occurs when run. **It prints the message on line 47 "printf("Reading the input file and writing data to output file simultaneously..."); then results in a segmentation fault (core dumped) I am using mobaXterm v11.0 (GNU nano 2.0.9) CSV (comma-separated values) is a popular file format to store tabular kind of data. Each record is in a separate line...
C++ Can someone please help me with this problem- commenting each line of code so I can understand how to solve this problem using the C++ programming language? I really need help understanding how to create a file for the program to read. Do I create the file in Visual basic or create a text file? I have the code, just need to know how to create the file for it to read. #include<fstream> #include<iostream> using namespace std; int main()...
Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...
Hello I need help with python programming here is my code # Trivia Challenge # Trivia game that reads a plain text file import sys def open_file(file_name, mode): """Open a file.""" try: the_file = open(file_name, mode) except IOError as e: print("Unable to open the file", file_name, "Ending program.\n", e) input("\n\nPress the enter key to exit.") sys.exit() else: return the_file def next_line(the_file): """Return next line from the trivia file, formatted.""" line = the_file.readline() line = line.replace("/", "\n") return line def next_block(the_file):...
Can some help me with my code I'm not sure why its not working. Thanks In this exercise, you are to modify the Classify Numbers programming example in this chapter. As written, the program inputs the data from the standard input device (keyboard) and outputs the results on the standard output device (screen). The program can process only 20 numbers. Rewrite the program to incorporate the following requirements: a. Data to the program is input from a file of an...
Java programming help My program wont run. could someone tell me why. everything seems correct to me... giving me the error: Exception in thread "main" java.lang.NumberFormatException: For input string: "Stud" at java.base/java.lang.NumberFormatException.forInputString(Unknown Source) at java.base/java.lang.Integer.parseInt(Unknown Source) at java.base/java.lang.Integer.parseInt(Unknown Source) at Util.readFile(Util.java:35) at Driver.main(Driver.java:8) _________________________________________________________________________________________________________________________ Program Prompt: Write a program to perform statistical analysis of scores for a class of students.The class may have up to 40 students.There are five quizzes during the term. Each student is identified by a four-digit...
PYTHON 3 Object Oriented Programming ***a9q3.py file below*** class GradeItem(object): # A Grade Item is anything a course uses in a grading scheme, # like a test or an assignment. It has a score, which is assessed by # an instructor, and a maximum value, set by the instructor, and a weight, # which defines how much the item counts towards a final grade. def __init__(self, weight, scored=None, out_of=None): """ Purpose: Initialize the GradeItem object. Preconditions: :param weight: the weight...
Please help. I need a very simple code. For a CS 1 class. Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "printall" - prints all student records (first name, last name, grade). "firstname name" - prints all students with...
Hello can someone help me in my code I left it as comment task #0, task#1, task#2a and task#2b the things that I am missing I'm using java domain class public class Pizza { private String pizzaCustomerName; private int pizzaSize; // 10, 12, 14, or 16 inches in diameter private char handThinDeep; // 'H' or 'T' or 'D' for hand tossed, thin crust, or deep dish, respecitively private boolean cheeseTopping; private boolean pepperoniTopping; private boolean sausageTopping; private boolean onionTopping; private boolean...