I need a program that generates a schedule for events involving multiple teams and activities based on the following requirements:

1. Flexible Number of Teams and Activities:

The number of teams (T) is an even number, up to 40 teams.
The number of activities (A) can vary and is less than or equal to the number of teams.
The program should accept user input for the number of teams and the number of activities.
It's not required that the number of teams is a multiple of the number of activities.
2. Automatic Determination of Rounds:

The program should automatically determine the number of rounds needed based on the number of teams and activities.
Each team must participate in every activity exactly once.
No team should repeat an activity across different rounds.
3. Scheduling Rules:

Unique Team in Each Activity per Round:
No team should appear more than once in any given activity column in the schedule.
This means that in each round, each activity has a unique set of teams.
Unique Team in Each Round Row:
No team should appear more than once in any round.
Teams Participate in All Activities:
Each team must participate in every activity exactly once throughout the entire schedule.
Rotation Similarity to Sudoku or Latin Square:
The assignment of teams to activities should be such that there are no repetitions in activity columns or round rows, similar to how numbers are placed in Sudoku or Latin squares.
4. Pairing Teams:

Random Pairings:
Teams within each activity are paired randomly in each round.
Minimize Repeat Matchups (Soft Rule):
Use a soft rule to minimize the number of times the same teams play against each other.
Some overlap in matchups is acceptable if necessary, but the program should aim to reduce repeat pairings as much as possible.
Flexible Pairings:
Since it's not always possible to avoid repeat matchups completely, especially with a large number of teams and limited rounds, the program should handle this gracefully.
5. Output Format:

Table Format:
The schedule should be generated in a clear table format.
Activities are displayed as columns (e.g., Activity A, Activity B, ...), and rounds are displayed as rows (e.g., Round 1, Round 2, ...).
Match Representation:
Each cell in the table represents the matchup for that activity in that round (e.g., "T1 vs. T2").
Complete Schedule:
The table should cover all rounds, with each team appearing exactly once per activity and per round, following the rules above.
6. Programming Requirements:

Programming Language:
Please write the program in Python.
Code Flexibility:
The program should be flexible and work with any even number of teams up to 40.
It should accommodate any reasonable number of activities less than or equal to the number of teams.
User Input:
The program should prompt the user to input the number of teams and the number of activities.
Input validation should be included to ensure the number of teams is an even number and other inputs are within acceptable ranges.
Randomization:
Use randomization functions appropriately to shuffle teams and generate random pairings.
Comments and Readability:
The code should be well-commented to explain the logic and steps taken.
Use clear variable names and structure for readability.
7. Error Handling and Validation:

The program should validate inputs and handle any errors gracefully.
Provide meaningful error messages if the inputs do not meet the requirements.
Ensure that the schedule generation logic accounts for scenarios where the number of teams is not a multiple of the number of activities.
8. Optional Enhancements (If Time Permits):

Graphical Representation:
Optionally, provide a graphical representation of the schedule (e.g., using a library like tabulate or pandas to display the table neatly).
Export Option:
Allow the user to export the schedule to a CSV or Excel file.
9. Examples:

Example with 10 teams and 5 activities:
The program should schedule 5 rounds.
In each round, teams are assigned to activities ensuring no team repeats an activity.
Teams are paired randomly within each activity, minimizing repeat matchups.
Sample Schedule Format:
Activity A	Activity B	Activity C	Activity D	Activity E
Round 1	T1 vs T2	T3 vs T4	T5 vs T6	T7 vs T8	T9 vs T10
Round 2	T3 vs T5	T1 vs T7	T2 vs T8	T4 vs T9	T6 vs T10
Round 3	...	...	...	...	...
Before you begin coding, please ensure that you fully understand the requirements. If you have any questions or need further clarification, please ask.