0

Just recently joined a python class and a new project was given to me where I have to print a statement that's predetermined, and if jersey numbers do not match up with certain positions-- it will say that it's invalid. Before this I only had access to block coding, so finding what's wrong with indentation and other minute details has been difficult. I've tried making my code simpler to find what's wrong with my programming (ex. changed 1 <= jersey_num <= 19 and new_position to just jersey_num == 1) and used incredibly wrong inputs, but my else statement doesn't seem to be firing. Any help?

team_name = input('What is the team name? ') 
playernum = int(input('How many players on the team?'))
total_payroll = int(input('What is the total player payroll?' ))
player_name = input('What is the name of the new player? ') 
new_position = input("What is the new player's position" ) 
jersey_num = int(input('What jersey number is the new player requesting? '))
player_sal = int(input("What is the new player's salary? "))

if 1 <= jersey_num <= 19 and new_position == "quarterback" or "running back" or "wide reciever" or "tight end" or "kicker" or "linebacker" or "defensive back":
    print(player_name, 'is a', new_position, 'and will wear number', jersey_num, 'for the team! The average player salary for the', team_name, 'went from', total_payroll + player_sal, 'with the new acquisition.') 
else:
    print('The requested jersey number', jersey_num, 'is not a valid number for the', new_position, 'position.')

1 Answers1

0

Because you are evaluating True or True

Here:

or "running back" or "wide reciever"

Strings are considered True in this situation. So it's True or True which will never allow you to enter the else statement.


You need to do new_position == position for each condition:

if 1 <= jersey_num <= 19 and new_position == "quarterback" or new_position == "running back" or new_position == "wide reciever" or new_position == "tight end" or new_position == "kicker" or new_position == "linebacker" or new_position == "defensive back":

or

positions = ["running back",
             "quarterback",
             "wide reciever",
             "tight end",
             "kicker",
             "linebacker",
             "defensive back"]

if (1 <= jersey_num) and (jersey_num <= 19) and (new_position in positions):
Freddy Mcloughlan
  • 4,129
  • 1
  • 13
  • 29