4.2k views
4 votes
Write a program that prompts users for the name and number of points of two basketball teams in main. Create one function to determine the possible scenarios and return the result. The function uses a nested if to calculate the winner (if any) or if both teams tied (have the same number of points).

User Ivanzoid
by
3.6k points

1 Answer

0 votes

Answer:

Following are the program in the Python Programming Language.

#define function

def winner(t1,t2,name1,name2):

#check the score of 1st team is greater

if(t1>t2):

print("{} is the winner\\".format(name1))

#check the score of 2nd team is greater

elif(t1<t2):

print("{} is the winner\\".format(name2))

#check that both team have same score

else:

print("They are tie\\")

#declare variables to get input from the user

name1=input("Enter the name of 1st team: ")

t1=input("Enter the score of {}: ".format(name1))

name2=input("Enter the name of 2nd team: ")

t2=input("Enter the score of {}: ".format(name2))

#call the function and pass arguments

winner(t1, t2, name1, name2)

Output:

Enter the name of 1st team: Air Ballers

Enter the score of Air Ballers: 350

Enter the name of 2nd team: Ankle Breakers

Enter the score of Ankle Breakers: 450

Ankle Breakers is the winner

Step-by-step explanation:

Following are the description of the program.

  • Firstly, define function 'winner()' and pass four arguments in the parameters which are 't1', 't2', 'name1', and 'name2', inside the function, set the if-else conditional statement to check that which team gets the higher score or they are tied.
  • Set four variables in which we get scores or names of the team from the user which are 't1', 't2', 'name1', and 'name2'.
  • Finally, we call the following function that is 'winner()' and pass the arguments.
User Ahmed Ramzi
by
3.7k points