Python Forum
Can Anyone Finish this off
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can Anyone Finish this off
#1
sorry im new here and new to python. can anyone help me finish this piece of code for me. 

really sorry im not sure how to put this code in a little box

#List of football Teams
>>> #List of Football players in the team
>>> #add a football team
>>> #add football players in the team
>>> #remove a football team
>>> #remove football players
>>> 

#These will be the starting teams availbe in the list
>>> teams = ["Arsenal", "Chelsea", "Liverpool", "Manchester United", "Manchester City"]

Arsenal = ["sample1, "Sample2", "Sample3", "Samlpe4"]

Chelsea = ["Test1", "Test2", "Test3"]

Liverpool = ["example1", "example2"]

Manchester United = ["player", "player1"]

Manchester City = ["player4", "player5"]


choice = "z"

while choice != "0":
    print " Options Menu "

    1: Add a Team
    2: Remove a Team
    3: Add Players to a Team
    4: Remove Players from a Team
    0: Quit

    choice = raw_input("Type The Number Realated to your Option(1,2,3,4(or 0 to quit):")
    
    if choice == "1":
           newTeam = raw_input("\nEnter a Team you would like to add: ")
           names.append(teams)

    elif choice == "2":
    removeTeam = raw_input("\nEnter the team you would like to remove: ")
    if removeTeams in teams:
    teams.remove(teams)
    else:
    print
    print NoTeam,"This Team is not on the list."
Reply
#2
That's not really going to work. Creating a new variable for each team is going to be a problem. Especially since 'Manchester United' is not a valid variable name (variable names can't have spaces in Python).

This would work much better with a dict:
teams = {'Arsenal': ['David Ospina', 'Kieran Gibbs'], 'Chelsea': ['Jock Cameron', 'Jack Cock'], ...}
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(Mar-25-2017, 01:45 AM)ichabod801 Wrote: That's not really going to work. Creating a new variable for each team is going to be a problem. Especially since 'Manchester United' is not a valid variable name (variable names can't have spaces in Python).

This would work much better with a dict:
teams = {'Arsenal': ['David Ospina', 'Kieran Gibbs'], 'Chelsea': ['Jock Cameron', 'Jack Cock'], ...}

thank you really appreciate that but what im struggling on is how to i add the option to add/remove players from the certain teams

thanks again
Reply
#4
teams['Chelsea'] = 'NewPlayer'
Reply
#5
Quote:teams['Chelsea'] = 'NewPlayer'

This will rewrite the whole list with NewPlayer as a single value.

teams['Chelsea'].append('NewPlayer' )
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#6
Quote:This will rewrite the whole list with NewPlayer as a single value.
You are correct
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Could someone help me finish this ASAP JimmyDricks 7 2,185 Dec-23-2021, 10:30 AM
Last Post: Larz60+
  how to check if file path finish on .csv danlopek14q 4 10,794 Apr-04-2021, 09:50 AM
Last Post: danlopek14q
  Need help to finish the hat on the snowman in this Python drawing soowoosamuel 1 3,309 Apr-10-2019, 06:31 AM
Last Post: j.crater

Forum Jump:

User Panel Messages

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