Conditional Statements Homeworks
Conditional Statements Homeworks
1. Write a program to determine the outcome of a football match by taking the number of goals
scored by two teams. If Team A scores more goals, print "Team A Wins", if Team B scores
more goals, print "Team B Wins", and if the scores are equal, print "Draw".
2. Create a program that rates a football player's performance based on the number of goals
scored in a season. If the player scores 0 goals, print "Poor Performance", between 1 and 5
goals, print "Average Performance", between 6 and 15 goals, print "Good Performance", and
more than 15 goals, print "Excellent Performance".
3. Write a program that takes match results (Win, Draw, Loss) for two teams in a group stage,
calculates their points based on wins, draws, and losses, and prints the top two teams
qualifying for the knockout stage.
4. Create a program to rate a cricket player's performance based on the number of runs scored in
a match. If the player scores less than 30 runs, print "Low Performance", between 30 and 60
runs, print "Medium Performance", and more than 60 runs, print "High Performance".
5. Write a program that calculates the result of a cricket match by taking the runs scored by two
teams. Print "Team A wins by X runs", "Team B wins by X runs", or "Match Drawn" based on
the comparison of the scores.
6. Write a program that calculates the batting average of a cricket player by taking the number of
innings, total runs scored, and number of times out. If the player was never out, print "Batting
Average Not Available"; otherwise, calculate and print the batting average as (Total Runs /
Times Out).
7. Create a program that takes a traffic light color input (Red, Yellow, or Green) and outputs the
corresponding action— “Stop” for Red, “Prepare to stop” for Yellow, and “Go” for Green. If
the input is invalid, print "Invalid color!".
8. A program that checks if a person qualifies for a personal loan with the following conditions:
age between 25 and 50, monthly income over $4000, no active loans, and a credit score
higher than 700. If they meet the criteria, print "Eligible for loan". If their credit score is
between 650 and 700, print "Eligible for loan with co-signer". Otherwise, print "Not eligible
for loan".
9. Write a program that calculates tax based on annual income, using different tax rates: 5% for
income under $20,000, 10% for income between $20,000 and $50,000, 15% for income
between $50,000 and $100,000, and 20% for income above $100,000. The program should
calculate and display the appropriate tax.
10. Implement a menu-driven calculator program that allows users to perform four operations:
addition, subtraction, multiplication, and division. The program should repeatedly display a
menu until the user selects "Exit". The operations should be performed based on user input
using a switch-case structure.
11. Create an ATM simulation program with options to check balance, deposit money, withdraw
money, and exit. The program should ask for a PIN, verify it, and allow the user to perform
actions. Ensure the balance doesn’t go negative and handle invalid choices appropriately.
12. Write a program that prompts the user to input a number (1–7) and prints the corresponding
day of the week (Monday to Sunday). The program should validate the input and prompt the
user again if the number is invalid, ensuring the input is between 1 and 7.
Solution
1.
Start
Input goalsA
Input goalsB
else
Print "Draw"
End
2.
Start
Input goals
if goals == 0
End
3.
Start
pointsA = 0
pointsB = 0
if resultsA == "Win"
pointsA = pointsA + 3
pointsA = pointsA + 1
if resultsB == "Win"
pointsB = pointsB + 3
pointsB = pointsB + 1
else
End
4.
Start
Input runs
if runs < 30
End
5.
Start
Input runsA
Input runsB
else
End