-
-
Save Mohamed2del/b3abf4be9ad03bbff3871361949b37e3 to your computer and use it in GitHub Desktop.
fname = input("Enter file name: ") | |
try : | |
fh = open(fname) | |
except: | |
print('Cannot open the file ',fname ,'please try again') | |
quit() | |
for line in fh : | |
line = line.upper() | |
line = line.rstrip() | |
print(line) |
What is the file name
Use words.txt as the file name
fname = input("Enter file name: ")
try:
fh = open(fname,"r")
except:
print("Cannot open the file ",fname ,"please try again")
quit()
x = fh.read()
y = x.upper()
w = y.strip()
print(w)
i don't understand how can we use "line" in "for line in fh" if we didn't define what was "line" first.
the code works fine the problem is with the browser you're using, especially Chrome, not compatible 100% with the graded external tool.
fname = input("Enter file name: ")
fh = open(fname)
fr= fh.read()
fs=fr.rstrip()
print(fs.upper()
Use words.txt as the file name
fname = input("Enter file name: ")
fh = open(fname)
for line in fh:
line = line.rstrip()
print(line.upper())
Use words.txt as the file name
fname = input("Enter file name: ")
fh = open(fname)
dh=fh.read( )
lx=dh.upper( ).rstrip( )
print (lx)
fname = input("Enter file name: ")
fh = open(fname)
for line in fh:
print(line.rstrip().upper())
Write a program that prompts for a file name, then opens that file and reads through the file, looking for lines of the form:
X-DSPAM-Confidence: 0.8475
Count these lines and extract the floating point values from each of the lines and compute the average of those values and produce an output as shown below. Do not use the sum() function or a variable named sum in your solution.
Use words.txt as the file name
fname = input("Enter file name: ")
fh = open(fname)
#fh.upper()
for x in fh:
y=x.rstrip()
print(y.upper())
The best Answer
fname = input("Enter file name: ")
try :
fh = open(fname)
except:
print('Cannot open the file ',fname ,'please try again')
quit()
txt = fh.read().strip().upper()
print(txt)
fname = input("Enter file name: ")
fh = open(fname,'r')
for li in fh:
rs=li.rstrip()
up=rs.upper()
print(up)
((or))
fname = input("Enter file name: ")
try:
fh = open(fname,'r')
except:
print('invalid file')
for li in fh:
rs=li.rstrip()
up=rs.upper()
print(up)