Skip to main content

Python Coding Tasks

You have at most 48 hours to complete the following challenges.

1. Optimus Prime... Number

The first 11 prime integers are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, and 31. A positive integer between 1 and 1000 (inclusive), other than the first 11 prime integers, is prime if it is not divisible by 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, and 31.

Write a program that prompts the user to enter a positive integer between 1 and 1000 (inclusive) and that outputs:

Level 1

whether the number is prime. If the number is not prime, then output all the numbers, from the list of the first 11 prime integers, which divide the number.

Level 2

all the numbers below the entered number that are prime numbers.

Level 3

all the numbers above the entered number (but only up to 1000) that are prime numbers.

2. TV and code

The screen size of a TV is given by the length of the rectangular diagonal. Traditional TVs come in 4:3 ratio, that is, the ratio of length to width is 4 to 3. This means, if the length is x inches, then the width is (3/4)x. LCD TVs come in 16:9 ratio.

Write a program that prompts the user to input the length of the diagonal (in inches) of the screen and allows the user to select which type of TV’s screen length, screen width, and screen area the user would like to calculate. Have the program display the desired results.

3. Manomi

Aliyu bought several acres of farm to grow and sell vegetables. Suppose that Aliyu wants to grow a maximum of two types of vegetables. Write a program that prompts Aliyu (or the user) to do the following:

  1. Enter the total farm area in acres.
  2. The number of vegetables (one or two) that the user wants to grow.
  3. If the user wants to grow two types of vegetables, then specify the portion, as a percentage, of the farm land used for each type of vegetable.
  4. Enter the seed cost, plantation cost, fertilizing cost, labor cost, for each acre.
  5. Enter vegetable selling price per acre.

Output the total revenue.

Output the profit/loss.

4. Tree Planting

Lex and Dauda want to plant evergreen trees along the back side of their yard. They do not want to have an excessive number of trees. Write a program that prompts the user to input the following:

  1. The length of the yard.
  2. The radius of a fully grown tree.
  3. The required space between fully grown trees.

The program outputs the number of trees that can be planted in the yard and the total space that will be occupied by the fully grown trees.

5. More Tree Planting

During each rainy season, Jelili and Omowunmi grow vegetables in their backyard and buy seeds and fertilizer from a local nursery. The nursery carries different types of vegetable fertilizers in various bag sizes.

When buying a particular fertilizer, they want to know the price of the fertilizer per pound and the cost of fertilizing per square foot.

Level 1

Write a program that prompts the user to enter the size of the fertilizer bag (in pounds), the cost of the bag (in naira), and the area (in square feet), that can be covered by the bag.

The program should output the desired result.

Level 2

Add another prompt for the user to also input their budget in naira. The program should now also output if the user's budget can cover the cost of gardening they want to undertake.

6. NBA Scout Pro

A scouting firm has hired you to write a program that analyses the data of a player. In this case, they want to analyse potential NBA drafts stats. Some stats to track include:

  • Player Name: The name of the player.
  • Game: The date of the game for which the statistics are being recorded.
  • Points: The number of points scored by the player in that game.
  • Rebounds: The number of rebounds the player had in that game.
  • Assists: The number of assists the player had in that game.
  • Three-Pointers Made: The number of three-pointers made by the player in that game.
  • Steals: The number of steals the player had in that game.
  • Blocks: The number of blocks the player had in that game.

These stats are currently saved in a csv file as shown below

right_click_academy.csv
name,game,points,rebounds,assists,3 pointers,steals,blocks
John Smith,1,35,9,4,1,2
Emily Johnson,1,28,10,5,4,0
Michael Brown,1,42,11,8,3,1
Jesse Davis,1,31,9,10,2,3
John Smith,2,25,9,4,1,1
Emily Johnson,2,30,10,5,4,3
Michael Brown,2,34,11,8,3,2
Jesse Davis,2,29,9,10,2,0

CSV File

Level 1

Write a function high_scores that takes 2 parameter: csv_file and player_name. player_name is a string and is the player's name. csv_file is the name of csv file containing data.

The function primarily reads the csv file and:

  • Finds out how many times the player achieved a new high record in either assists, rebounds or points and returns the values in a dictionary like this:

    {
    points: 2,
    rebounds: 3,
    assists: 1
    }

Level 2

Write a function high_score_games that takes 2 parameter: csv_file and player_name. player_name is a string and is the player's name. csv_file is the name of csv file containing data.

The function primarily reads the csv file and:

  • Finds out the games where the player achieved a new high record in either assists, rebounds or points and returns the values in a dictionary like this:

    {
    points: [2,7],
    rebounds: [3],
    assists: [3,4,5]
    }

Level 3

Write a function triple_double_counter that takes 2 parameter: csv_file and player_name. player_name is a string and is the player's name. csv_file is the name of csv file containing data.

The function primarily reads the csv file and:

  • Finds out how many times the player got a triple double and in which games they got those triple doubles. Return the result in a dictionary like this:

    {
    count: 3,
    games: [3,5,7]
    }

Level 4

Write a function goat_awards that takes 1 parameter: csv_file where csv_file is the name of csv file containing data.

The function primarily reads the csv file and:

  • Finds out who scored the most points of all the players
  • Finds out who recorded the most assists of all the players
  • Finds out who recoreded the most rebounds of all the players:
  • Finds out who recoreded the most blocks of all the players:

It should return a dictionary like this:

{
most_points: ['Lex Lu',356],
most_assists: ['Lex Lu',356],
most_reboundss: ['Lex Lu',356],
most_blocks: ['Lex Lu',356]
}