Question: a) A Python for loop iterates? Describe what that means using the first two for loops in the example code. b) What does the range()

a) A Python for loop iterates? Describe what that means using the first two for

loops in the example code.

b) What does the range() function do? What happens when one, two, and three

arguments are used with the range function?

c) In most languages, altering the counting variable that is being used to control a

for loop in the body of the loop can cause problems and lead to the loop not

executing the desired number of times. In the last for loop in the example, the

count variable is being altered. Is this causing problems with the number of loop

repeats? Why or why not?

c) Strings

Code

def main():

string_val = input('Enter a string value: ')

#Built-in function

print('The string contains', len(string_val), 'characters')

#String iteration

print(' Each character in the string is:')

for ch in string_val:

print(ch)

#string methods

print(' THe string all upper case is:', string_val.upper())

print(' THe string all lower case is:', string_val.lower())

#string concatenation

print(' THe string concatenated is:', string_val +

string_val, end = ' ')

#string splicing

fullname = input('Enter your first and last name: ')

blank_space = fullname.index(' ')

print(' Your first name is:', fullname[0:blank_space])

print(' Your last name is:', fullname[blank_space+1:])

main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Psychology Questions!