Question

#complete the following lines of code wherever indicated. 5 question 20 points a piece #you may use your book and internet bu

Python

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Below is a screen shot of the python program to check indentation. Comments are given on every line explaining the code.
1 # QUESTION 1: 2 -with open(exam_file.txt,r) as f: #open file 3 C = 0 for line in f: #Loop line by line 5 C += 1 #increm
Below is the output of the program:
Question 1 output:
1 2 exam_file.txt fedur this is line 1 this is line 2 this is line 3 this is line 4 3 4this is line 1 this is line 3

Question 2 output:
Open A question 2.out --/Projects/lib this is line 1 this is line 2 this is line 3 this is line 4

Question 3 output:
I Process finished with exit code 0

Question 4 output:
I will join BEEP BEEP on his adventure to the BEEP to find the BEEP Process finished with exit code 0

Ouestion 5 output:
Enter one topping: olives This pizza contains peperoni, olives, pineapple, Process finished with exit code 0

Below is the code to copy:

#CODE STARTS HERE----------------
# QUESTION 1:
with open("exam_file.txt","r") as f: #open file
   c = 0
   for line in f: #Loop line by line
      c += 1 #increment by 1
      if c % 2 != 0: #if odd lines, then enter
         print(line)

#QUESTION 2:
fout = open("question2.out","a") #Open file to write
with open("exam_file.txt","r") as f: #open file
   for line in f: #Loop line by line
      words = line.strip().split()
      for w in words: #loop word by word
         fout.write(w+"\n") #write to file
fout.close()

#QUESTION 3:
import re
line = "1. Hello Mr. President, I am Nathan D. Green and this is my friend Johan T. Popsicle"
li = re.findall(" [A-Z]\. ", line) #Regex matches "space"+"1 A-Z character"+" . character"+ "space"
for x in li:
   print(x[1])

#QUESTION 4:
import re
sentence = "I will join Jon Snow on his adventure to the North to find the Wildlings"
print(re.sub(r' [B-DF-HJ-NP-TV-Z][^\s]*', ' BEEP ', sentence))

#QUESTION 5:
inp = input("Enter one topping: ")
toppings = {'peperoni':True,'olives':False,'pineapple':True,'sausage':False,'jalapenos':False}
toppings[inp.lower()] = True
print("This pizza contains ", end="")
for x, y in toppings.items():
   if y is True:
      print(x, end=", ")

#CODE ENDS HERE-----------------
Add a comment
Know the answer?
Add Answer to:
Python #complete the following lines of code wherever indicated. 5 question 20 points a piece #you...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python   #complete the following lines of code wherever indicated. 5 question 20 points a piece #you...

    Python   #complete the following lines of code wherever indicated. 5 question 20 points a piece #you may use your book and internet but no form of messaging or communication #QUESTION 1 #Read in the file exam_file.txt #Print to the console every other line #QUESTION 2 #Read in exam_file.txt #split file into words #write to a file called question2.out that contains 1 word per line (words can occur more than once) #QUESTION 3 # Print out all the Middle Initials in...

  • Python 3.6 Question 12 (20 points) Write a function named wordLengths. The function wordLengths takes two...

    Python 3.6 Question 12 (20 points) Write a function named wordLengths. The function wordLengths takes two parameters: 1. inFile, a string that is the name of an input file 2. outFile, a string that is the name of an output file The input file exists when wordLengths is called; wordLengths must create the file outFile. The input file contains only letters and white space For each line of the input file, wordLengths should identify the length of the longest word...

  • I need python help .. I need to know if a user were to input 3...

    I need python help .. I need to know if a user were to input 3 commands to a program and run it such as specify: Usage: ./filemaker INPUTCOMMANDFILE OUTPUTFILE RECORDCOUNT (./filemaker is the program)( (INPUTCOOMANDFUILE= a text file that contains key words that need to be searched through then decided what to do ) (RECORDCOUNT= number) Given an input file that contains the following: That specifies the text, then the output, and the number of times to be repeated...

  • What are the outputs for each question PYTHON Question 6 bools = [True, 0>-1, not not...

    What are the outputs for each question PYTHON Question 6 bools = [True, 0>-1, not not True, 2%2 == 0, True and False] index = 0 while bools[index]: index += 1 print(index) a) 0 b) 1 c) 2 d) 3 e) none of the above Question 7 for i in range(2): for j in range(1): print(i, j, end = " ") a) no output b) 0 0 1 0 2 0 c) 0 0 0 1 1 0 1 1...

  • Please write the following code as simple as possible in python: You will need to define...

    Please write the following code as simple as possible in python: You will need to define a function with four arguments. Here is what I used: > def find_matches(file1.txt, output1.txt, strings, value): file1.txt will contain a list of various strings. The program must copy from the first argument, and it should be written in the second argument (the second file, "output1.txt"). The third and fourth arguments will determine which specific strings will be copied over to the second file. For...

  • Not yet answered Marked out of 1.00 Flag question Question text What is the value of...

    Not yet answered Marked out of 1.00 Flag question Question text What is the value of the following Python expression? not(True and False) Select one: True False Question 2 Not yet answered Marked out of 1.00 Flag question Question text Consider the following Python program. fin = open('words.txt') for line in fin: word = line.strip() print(word) What does the program loop over? Select one: a. Lines in a file b. Lines in a list c. Words in a dictionary d....

  • In this lab you will write a spell check program. The program has two input files:...

    In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...

  • Write the Java code for the class WordCruncher. Include the following members:

    **IN JAVAAssignment 10.1 [95 points]The WordCruncher classWrite the Java code for the class WordCruncher. Include the following members:A default constructor that sets the instance variable 'word' to the string "default".A parameterized constructor that accepts one String object as a parameter and stores it in the instance variable. The String must consist only of letters: no whitespace, digits, or punctuation. If the String parameter does not consist only of letters, set the instance variable to "default" instead. (This restriction will make...

  • For this week's lab, you will use two of the classes in the Java Collection Framework:...

    For this week's lab, you will use two of the classes in the Java Collection Framework: HashSet and TreeSet. You will use these classes to implement a spell checker. Set Methods For this lab, you will need to use some of the methods that are defined in the Set interface. Recall that if set is a Set, then the following methods are defined: set.size() -- Returns the number of items in the set. set.add(item) -- Adds the item to the...

  • For this week's lab, you will use two of the classes in the Java Collection Framework:...

    For this week's lab, you will use two of the classes in the Java Collection Framework: HashSet and TreeSet. You will use these classes to implement a spell checker. Set Methods For this lab, you will need to use some of the methods that are defined in the Set interface. Recall that if set is a Set, then the following methods are defined: set.size() -- Returns the number of items in the set. set.add(item) -- Adds the item to the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT