233k views
3 votes
1.Create myFriends list with three names Tom, Jerry, Doggy then write python code to print the second name from the list.

2.Write a statement that increases the value of numCars by one.

3.Write code to convert string "This is my midterm" to a list

User Ortund
by
8.8k points

1 Answer

2 votes

Final answer:

To print the second name from the myFriends list in Python, use myFriends[1]. To increase the value of numCars by one, use numCars += 1. To convert a string into a list, use the split() method on the string.

Step-by-step explanation:

Python Programming Questions

To address the first part of the question:

  1. Create a list called myFriends with the names 'Tom', 'Jerry', 'Doggy' in Python:

myFriends = ['Tom', 'Jerry', 'Doggy']
print(myFriends[1]) # This will print 'Jerry', the second name in the list.

For the second part:

  1. To increase the value of numCars by one, you could use the following statement:

numCars += 1

Lastly, for the third part:

  1. To convert a string to a list, you can use the split() method. Here's how you can convert the string "This is my midterm" into a list:

string_to_convert = "This is my midterm"
converted_list = string_to_convert.split()
print(converted_list) # This will print ['This', 'is', 'my', 'midterm']

User Aamir Afridi
by
8.2k points