Can you please write all of the following programs in Python 3? Also, can you pl
ID: 3732755 • Letter: C
Question
Can you please write all of the following programs in Python 3? Also, can you please show all the outputs?
Assignment 6 uses assignment 5 questions and you need to write them to the database.
Assignment # 5 Quetions to be used for assigement #6.
ASSIGNMENT #6
(Create an investment-value calculator) Write a program that calculates the future value of an investment at a given interest rate for a specified number of years. The formula for the calculation is as follows: futureValue 1. investmentAmount (1 + monthlyinterestRate)/ (years *12) 7% Investment Calculator Investment Amount Veare Annual Interest Rate Future Value 10000 1102266 Celcuiste Use text fields for users to enter the investment amount, years, and interest rate. Display the future amount in a text field when the user clicks the Calculate button. (Alternate two messages) Write a program to change, with a left mouse click, between two messages displayed on a canvas, "Programming is fun" and "It is fun to program,". 2. (Traffic lights) Write a program that simulates a traffic light. The program lets the user select one of three lights: red, yellow, or green. When a radio button is selected, the light is turned on, and only one light can be on at a time (see Figure a-b). No light is on when the program starts. 3.Explanation / Answer
Assignment 6
1) removed all occurences of wrod from file
def replaceText(filename, word):
linetext = ""
inputFile = open(filename)
for line in inputFile:
linetext += line.replace(word, "")
inputFile.close()
#print(linetext)
outfile = open(filename, "w+")
outfile.write(linetext)
outfile.flush()
outfile.close
#inputFile = open(filename, "w+")
#inputFile.write(linetext)
#inputFile.close()
def main():
filename = input("Enter file name: ")
if os.path.exists(filename):
word = input("Enter word to replace: ")
replaceText(filename, word)
else:
print("File doesn't exist")
main() # to call main() method
2) count all occurences of words, characters and lines
import os.path
def countOccurences(filename):
lines = 0
words = 0
chars = 0
with open(filename, 'r') as fileToRead:
for line in fileToRead:
wordsInLine = line.split()
lines += 1
words += len(wordsInLine)
chars += len(line)
print("%s characters" %(chars))
print("%s words" %(words))
print("%s lines" %(lines))
def main():
filename = input("Enter file name: ")
if os.path.exists(filename):
countOccurences(filename)
else:
print("File doesn't exist")
main()
3) create random integers
import os.path
import random
def writeRandomNumbers(filename):
numbers = ""
randNumber = []
sortedNumber = ""
with open(filename, 'w+') as fileToWrite:
for num in range(1, 101):
numbers = numbers+" "+str(random.randint(1, 100))
#print(numbers)
fileToWrite.write(numbers)
fileToWrite.flush()
fileToWrite.close()
with open(filename, "r") as fileToRead:
for line in fileToRead:
#print(line.split(" "))
randNumber = [int(x) for x in line.split(" ") if len(x) > 0]
#print(randNumber)
with open(filename, 'w+') as fileToWrite:
for elem in sorted(randNumber, key=int):
sortedNumber = sortedNumber+" "+str(elem)
fileToWrite.write(sortedNumber)
fileToWrite.flush()
fileToWrite.close()
def main():
filename = input("Enter file name: ")
if os.path.exists(filename):
print("The file already exist")
else:
writeRandomNumbers(filename)
main()
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.