Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dealing with list
#1
## Its part of my boot camp Task

● Imagine you want to store the names of three of your friends in a list of
strings. Create a list variable called friends_names , and write the syntax to
store the full names of three of your friends.
● Now, write statements to print out the name of the first friend, then the
name of the last friend, and finally the length of the list.
● Now, define a list called friends_ages that stores the age of each of your
friends in a corresponding manner, i.e., the first entry of this list is the age
of the friend named first in the other list.

My Code so far

friends_names = ["Paul Jacobs","Mark Noble","John Pine"]#Create a list variable called friends_names

print(friends_names[0])#print out the name of the first friend
print(friends_names[2])#name of the last friend
print(len(friends_names))#the length of the list
Reply
#2
Do you have a question? What you have coded looks good so far, so now you just need to complete the last bullet point:

● Now, define a list called friends_ages that stores the age of each of your
friends in a corresponding manner, i.e., the first entry of this list is the age
of the friend named first in the other list.
Reply
#3
Last friends name is correct only if there are three friends. Last item in any sequence in Python is with index -1, so whatever number of friends you have friends_names[-1] will always give last friends name.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Dealing with duplicates to an Excel sheet DistraughtMuffin 6 3,218 Oct-28-2020, 05:16 PM
Last Post: Askic
  Dealing with errors in input souprqtpie 7 3,384 Apr-10-2019, 11:04 AM
Last Post: souprqtpie

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020