Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this assinment it must be written in Python Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on

I need help with this assinment it must be written in Python

Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32 Type "copyright", "credits" or "license()" for more information. >>> import os >>> getcwd() Traceback (most recent call last): File "", line 1, in getcwd() NameError: name 'getcwd' is not defined >>> dir >>> os.getcwd >>> os.getcwd() 'D:\\' >>> os.chdir("c:\\") >>> os.listdir() ['$GetCurrent', '$Recycle.Bin', 'autoexec.bat', 'bootmgr', 'BOOTNXT', 'Config.Msi', 'config.sys', 'Course Technology', 'Documents and Settings', 'inetpub', 'Intel', 'Logs', 'mydrivers', 'OneDriveTemp', 'pagefile.sys', 'PerfLogs', 'Program Files', 'ProgramData', 'Recovery', 'swapfile.sys', 'System Volume Information', 'Users', 'Windows', 'Windows.old', 'Windows10Upgrade'] >>> file = open("maximum.py", r) Traceback (most recent call last): File "", line 1, in file = open("maximum.py", r) NameError: name 'r' is not defined >>> f = open("maximum1.py, r") Traceback (most recent call last): File "", line 1, in f = open("maximum1.py, r") FileNotFoundError: [Errno 2] No such file or directory: 'maximum1.py, r' >>> f = open('maximum1.py, r') Traceback (most recent call last): File "", line 1, in f = open('maximum1.py, r') FileNotFoundError: [Errno 2] No such file or directory: 'maximum1.py, r' >>> os.chdir('D:\\) SyntaxError: EOL while scanning string literal >>> os.chdir("D:\\") >>> os.chdir("D:\\") """ Program: Lab7Commands Author: David Jeffery Date: October 2, 2016 Description: Illustrate several of the ways to work with files in Python. We will work through these in lab using the command line prompt. Analysis: Input: PythonFiles.txt and numbers.txt (after it is created) Output: numbers.txt Caculations: total the numbers written to numbers.txt """ # read in an entire file import os # os.chdir("u:") # change based on where you want to read and write files f = open("PythonFiles.txt",'r') text = f.read() print(text) # read in a file line by line f = open("PythonFiles.txt",'r') for line in f: print(line) #write out a text file with numbers f = open("numbers.txt",'w') for count in range(10): f.write(str(count)+" ") f.close() #read back in the numbers and display the sum f = open("numbers.txt",'r') sum = 0 for line in f: line = line.strip() number = int(line) sum = sum + number print("Sum = ", sum) # Exit the program print("Thank you for using our program")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

a sin(2x) x Let f(x)=2x+1 In(be)

Answered: 1 week ago