Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a) Besides the len() function, what other built-in functions can be used with strings? b) The for loop shows that string objects are iterable. What

a) Besides the len() function, what other built-in functions can be used with strings?

b) The for loop shows that string objects are iterable. What does that mean?

c).upper() and .lower() are string methods. What I a method and how is it

similar and different from a function?

d)What happens when a string is sliced? What would happen if there are two blank

spaces in the string?

d) Text files

Note: If no path is included, files will be placed in the same folder as the Python source

code.

Code:

def main():

# Block 1

namefile = open('names1.txt','w')

for count in range(5):

name = input('Enter a name: ')

namefile.write(name)

namefile.close()

namefile = open('names1.txt','r')

for name in namefile:

print(name)

namefile.close()

#=========================

#Block 2

namefile = open('names2.txt','w')

for count in range(5):

name = input('Enter a name: ')

namefile.write(name + ' ')

namefile.close()

namefile = open('names2.txt','r')

for name in namefile:

print(name)

namefile.close()

#========================

#block 3

namefile = open('names2.txt','w')

for count in range(5):

name = input('Enter a name: ')

namefile.write(name + ' ')

namefile.close()

namefile = open('names2.txt','r')

for name in namefile:

print(name.rstrip())

namefile.close()

#=======================

#Block 4

numfile = open('numbers.txt','w')

for count in range(5):

int_num = int(input('Enter an integer value: '))

numfile.write(str(int_num) + ' ')

numfile.close()

numfile = open('numbers.txt','r')

total = 0

for int_num in numfile:

print(int_num.rstrip())

total += int_num

numfile.close()

#=======================================

Block 5

numfile = open('numbers.txt','r')

total = 0

for int_num in numfile:

int_num = int(int_num)

print(int_num)

total += int_num

print('The total of all numbers in the file is:', total)

numfile.close()

main()

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

An Introduction to Management Science Quantitative Approach to Decision Making

Authors: David R. Anderson, Dennis J. Sweeney, Thomas A. Williams, Jeffrey D. Camm, James J. Cochran

15th edition

978-1337406529

More Books

Students also viewed these Psychology questions

Question

Can Eagle lower its selling price to Cherokee? Explain your answer.

Answered: 1 week ago

Question

127. Identify four specialized financial analysis tools.

Answered: 1 week ago

Question

125. Identify and describe limitations of ratio analysis.

Answered: 1 week ago