Question
This program generates a random number for two variables. One will be for the BYU women's soccer team and the other will be for their
This program generates a random number for two variables. One will be for the BYU women's soccer team and the other will be for their Opponent. I want you to write a program that asks the user for a team name (i.e. BYU women's soccer) using a prompt and how many games make up the soccer season (i.e. 10).
You will use the number of games within a FOR loop that will prompt the user to enter in the opponent's name for each game processed.
The team name entered will play a bunch of other teams (opponents) in the season but you are only storing data for that team (BYU women's soccer) you entered.
For example, the program will prompt you for your team name (BYU women's soccer). After which, it will prompt you for the number of games to play. As a recommendation, keep the number low or you will be typing a lot. For each game that is played, you will have to enter the opponent's name.
Then generate a random number between 0 and 10 for the first team you entered (your team/BYU) and another random number with the same range for the opponent. Determine who won the game by seeing who had a higher number (points) generated. Keep track of the number of times your team won (meaning you will need a variable to keep track of the wins and one for the losses or you can subtract the total number of games from wins to calculate the losses).
WHILE there is a tie in one of the games (both random numbers generated are the same value), you will continue to generate random numbers for the home team and opponent team until the tie is broken (the numbers are no longer equal). In other words, there are no tie scores allowed.
When one game is over and you have determined if your team won or lost and updated the wins and losses for your team, you will be prompted to enter the next opponent's name until all games have been played.
Once the season is over (all games played), you will display the team name that you entered (i.e. BYU) and their record.
For example:
BYU 12-2
IF the team has won at least 75% of their games then print out "NCAA Women's Soccer Tournament". If the team has won at least 50% but less than 75% (you don't need to worry about an upper limit since the first IF statement handles this) then print out "You had a good season". Otherwise, print out "Your team needs to practice!".
For example:
BYU 12-2
NCAA Women's Soccer Tournament
Make sure your prompts are informative for the user input.
import random
#Prompt the user for their team name
team_name = input("Enter the name of your team : ")
#Prompt the user for the total number of games
num_games = int(input("Enter the total number of games that they will play : "))
# Initialize score variables
wins = 0
losses = 0
#I in Range for the games/math / loop
for i in range(num_games):
#Prompt user to enter opponent's name
opponent_name = input("Enter the team name of the opposing team : ")
#Generate random numbers between 0 and 10
team_score = random.randint(0, 10)
opponent_score = random.randint(0, 10)
#Break when there are ties
while team_score == opponent_score:
team_score = random.randint(0, 10)
opponent_score = random.randint(0, 10)
break
#Check who won
if team_score > opponent_score:
wins += 1
else:
losses += 1
#Display team name and record
print(team_name, wins)
Step by Step Solution
3.38 Rating (160 Votes )
There are 3 Steps involved in it
Step: 1
import random Prompt the user for their team name teamname inputEnter the name of your team Prompt t...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started