← Computer Programming I

Variant 1. Cinema tickets

Create a file named assignment.py. Write a program that calculates the total cost of cinema tickets. The program must also check if the customer has enough money.

Use this table to find the price of one ticket:

Is the customer a student? Number of tickets Price per ticket
yes 5 or more 8
yes Fewer than 5 10
no 5 or more 10
no Fewer than 5 12

Your program must:

  • Use input() to ask for three values:
    • The number of tickets.
    • Is the customer a student? The answer is yes or no.
    • The amount of money the customer has.
  • Convert the number of tickets and the amount of money to integers.
  • Use if, elif, and else with Boolean expressions to choose the price per ticket. Follow the table above.
  • Calculate and store the total cost.
  • Print the price per ticket and total cost using f-strings.
  • Compare the money the customer has with the total cost:
    • If the customer has more money than needed, calculate and print how much money will be left after buying the tickets.
    • If the customer has exactly enough money, print Exactly enough money.
    • If the customer does not have enough money, calculate and print how much more money they need.

Example 1

Enter the number of tickets: 6
Are you a student? (yes/no): yes
Enter the money you have: 50
Price per ticket: 8
Total cost: 48
Money left: 2

Example 2

Enter the number of tickets: 4
Are you a student? (yes/no): yes
Enter the money you have: 40
Price per ticket: 10
Total cost: 40
Exactly enough money

Example 3

Enter the number of tickets: 5
Are you a student? (yes/no): no
Enter the money you have: 45
Price per ticket: 10
Total cost: 50
More money needed: 5

Example 4

Enter the number of tickets: 4
Are you a student? (yes/no): no
Enter the money you have: 50
Price per ticket: 12
Total cost: 48
Money left: 2

Variant 2. Swimming pool passes

Create a file named assignment.py. Write a program that calculates the total cost of swimming pool passes. Each pass allows one visit to the pool. The program must also check if the customer has enough money.

Use this table to find the price of one pass:

Is the customer a student? Number of passes Price per pass
yes 4 or more 6
yes Fewer than 4 8
no 4 or more 8
no Fewer than 4 10

Your program must:

  • Use input() to ask for three values:
    • The number of passes.
    • Is the customer a student? The answer is yes or no.
    • The amount of money the customer has.
  • Convert the number of passes and the amount of money to integers.
  • Use if, elif, and else with Boolean expressions to choose the price per pass. Follow the table above.
  • Calculate and store the total cost.
  • Print the price per pass and total cost using f-strings.
  • Compare the money the customer has with the total cost:
    • If the customer has more money than needed, calculate and print how much money will be left after buying the passes.
    • If the customer has exactly enough money, print Exactly enough money.
    • If the customer does not have enough money, calculate and print how much more money they need.

Example 1

Enter the number of passes: 5
Are you a student? (yes/no): yes
Enter the money you have: 40
Price per pass: 6
Total cost: 30
Money left: 10

Example 2

Enter the number of passes: 3
Are you a student? (yes/no): yes
Enter the money you have: 24
Price per pass: 8
Total cost: 24
Exactly enough money

Example 3

Enter the number of passes: 4
Are you a student? (yes/no): no
Enter the money you have: 25
Price per pass: 8
Total cost: 32
More money needed: 7

Example 4

Enter the number of passes: 3
Are you a student? (yes/no): no
Enter the money you have: 40
Price per pass: 10
Total cost: 30
Money left: 10

Variant 3. Museum tickets

Create a file named assignment.py. Write a program that calculates the total cost of museum tickets. The program must also check if the customer has enough money.

Use this table to find the price of one ticket:

Is the customer a student? Number of tickets Price per ticket
yes 6 or more 5
yes Fewer than 6 7
no 6 or more 7
no Fewer than 6 9

Your program must:

  • Use input() to ask for three values:
    • The number of tickets.
    • Is the customer a student? The answer is yes or no.
    • The amount of money the customer has.
  • Convert the number of tickets and the amount of money to integers.
  • Use if, elif, and else with Boolean expressions to choose the price per ticket. Follow the table above.
  • Calculate and store the total cost.
  • Print the price per ticket and total cost using f-strings.
  • Compare the money the customer has with the total cost:
    • If the customer has more money than needed, calculate and print how much money will be left after buying the tickets.
    • If the customer has exactly enough money, print Exactly enough money.
    • If the customer does not have enough money, calculate and print how much more money they need.

Example 1

Enter the number of tickets: 7
Are you a student? (yes/no): yes
Enter the money you have: 40
Price per ticket: 5
Total cost: 35
Money left: 5

Example 2

Enter the number of tickets: 5
Are you a student? (yes/no): yes
Enter the money you have: 35
Price per ticket: 7
Total cost: 35
Exactly enough money

Example 3

Enter the number of tickets: 6
Are you a student? (yes/no): no
Enter the money you have: 40
Price per ticket: 7
Total cost: 42
More money needed: 2

Example 4

Enter the number of tickets: 5
Are you a student? (yes/no): no
Enter the money you have: 50
Price per ticket: 9
Total cost: 45
Money left: 5

Variant 4. Notebooks

Create a file named assignment.py. Write a program that calculates the total cost of notebooks. The program must also check if the customer has enough money.

Use this table to find the price of one notebook:

Is the customer a student? Number of notebooks Price per notebook
yes 8 or more 3
yes Fewer than 8 4
no 8 or more 4
no Fewer than 8 5

Your program must:

  • Use input() to ask for three values:
    • The number of notebooks.
    • Is the customer a student? The answer is yes or no.
    • The amount of money the customer has.
  • Convert the number of notebooks and the amount of money to integers.
  • Use if, elif, and else with Boolean expressions to choose the price per notebook. Follow the table above.
  • Calculate and store the total cost.
  • Print the price per notebook and total cost using f-strings.
  • Compare the money the customer has with the total cost:
    • If the customer has more money than needed, calculate and print how much money will be left after buying the notebooks.
    • If the customer has exactly enough money, print Exactly enough money.
    • If the customer does not have enough money, calculate and print how much more money they need.

Example 1

Enter the number of notebooks: 9
Are you a student? (yes/no): yes
Enter the money you have: 30
Price per notebook: 3
Total cost: 27
Money left: 3

Example 2

Enter the number of notebooks: 7
Are you a student? (yes/no): yes
Enter the money you have: 28
Price per notebook: 4
Total cost: 28
Exactly enough money

Example 3

Enter the number of notebooks: 8
Are you a student? (yes/no): no
Enter the money you have: 30
Price per notebook: 4
Total cost: 32
More money needed: 2

Example 4

Enter the number of notebooks: 7
Are you a student? (yes/no): no
Enter the money you have: 40
Price per notebook: 5
Total cost: 35
Money left: 5

Variant 5. Bus tickets

Create a file named assignment.py. Write a program that calculates the total cost of bus tickets. The program must also check if the customer has enough money.

Use this table to find the price of one ticket:

Is the customer a student? Number of tickets Price per ticket
yes 10 or more 4
yes Fewer than 10 5
no 10 or more 5
no Fewer than 10 6

Your program must:

  • Use input() to ask for three values:
    • The number of tickets.
    • Is the customer a student? The answer is yes or no.
    • The amount of money the customer has.
  • Convert the number of tickets and the amount of money to integers.
  • Use if, elif, and else with Boolean expressions to choose the price per ticket. Follow the table above.
  • Calculate and store the total cost.
  • Print the price per ticket and total cost using f-strings.
  • Compare the money the customer has with the total cost:
    • If the customer has more money than needed, calculate and print how much money will be left after buying the tickets.
    • If the customer has exactly enough money, print Exactly enough money.
    • If the customer does not have enough money, calculate and print how much more money they need.

Example 1

Enter the number of tickets: 11
Are you a student? (yes/no): yes
Enter the money you have: 50
Price per ticket: 4
Total cost: 44
Money left: 6

Example 2

Enter the number of tickets: 9
Are you a student? (yes/no): yes
Enter the money you have: 45
Price per ticket: 5
Total cost: 45
Exactly enough money

Example 3

Enter the number of tickets: 10
Are you a student? (yes/no): no
Enter the money you have: 45
Price per ticket: 5
Total cost: 50
More money needed: 5

Example 4

Enter the number of tickets: 9
Are you a student? (yes/no): no
Enter the money you have: 60
Price per ticket: 6
Total cost: 54
Money left: 6

Variant 6. Printed posters

Create a file named assignment.py. Write a program that calculates the total cost of printed posters. The program must also check if the customer has enough money.

Use this table to find the price of one poster:

Is the customer a student? Number of posters Price per poster
yes 6 or more 7
yes Fewer than 6 9
no 6 or more 9
no Fewer than 6 11

Your program must:

  • Use input() to ask for three values:
    • The number of posters.
    • Is the customer a student? The answer is yes or no.
    • The amount of money the customer has.
  • Convert the number of posters and the amount of money to integers.
  • Use if, elif, and else with Boolean expressions to choose the price per poster. Follow the table above.
  • Calculate and store the total cost.
  • Print the price per poster and total cost using f-strings.
  • Compare the money the customer has with the total cost:
    • If the customer has more money than needed, calculate and print how much money will be left after buying the posters.
    • If the customer has exactly enough money, print Exactly enough money.
    • If the customer does not have enough money, calculate and print how much more money they need.

Example 1

Enter the number of posters: 7
Are you a student? (yes/no): yes
Enter the money you have: 60
Price per poster: 7
Total cost: 49
Money left: 11

Example 2

Enter the number of posters: 5
Are you a student? (yes/no): yes
Enter the money you have: 45
Price per poster: 9
Total cost: 45
Exactly enough money

Example 3

Enter the number of posters: 6
Are you a student? (yes/no): no
Enter the money you have: 50
Price per poster: 9
Total cost: 54
More money needed: 4

Example 4

Enter the number of posters: 5
Are you a student? (yes/no): no
Enter the money you have: 60
Price per poster: 11
Total cost: 55
Money left: 5

Variant 7. Pens

Create a file named assignment.py. Write a program that calculates the total cost of pens. The program must also check if the customer has enough money.

Use this table to find the price of one pen:

Is the customer a student? Number of pens Price per pen
yes 10 or more 2
yes Fewer than 10 3
no 10 or more 3
no Fewer than 10 4

Your program must:

  • Use input() to ask for three values:
    • The number of pens.
    • Is the customer a student? The answer is yes or no.
    • The amount of money the customer has.
  • Convert the number of pens and the amount of money to integers.
  • Use if, elif, and else with Boolean expressions to choose the price per pen. Follow the table above.
  • Calculate and store the total cost.
  • Print the price per pen and total cost using f-strings.
  • Compare the money the customer has with the total cost:
    • If the customer has more money than needed, calculate and print how much money will be left after buying the pens.
    • If the customer has exactly enough money, print Exactly enough money.
    • If the customer does not have enough money, calculate and print how much more money they need.

Example 1

Enter the number of pens: 11
Are you a student? (yes/no): yes
Enter the money you have: 25
Price per pen: 2
Total cost: 22
Money left: 3

Example 2

Enter the number of pens: 9
Are you a student? (yes/no): yes
Enter the money you have: 27
Price per pen: 3
Total cost: 27
Exactly enough money

Example 3

Enter the number of pens: 10
Are you a student? (yes/no): no
Enter the money you have: 25
Price per pen: 3
Total cost: 30
More money needed: 5

Example 4

Enter the number of pens: 9
Are you a student? (yes/no): no
Enter the money you have: 40
Price per pen: 4
Total cost: 36
Money left: 4

Variant 8. Sandwiches

Create a file named assignment.py. Write a program that calculates the total cost of sandwiches. The program must also check if the customer has enough money.

Use this table to find the price of one sandwich:

Is the customer a student? Number of sandwiches Price per sandwich
yes 4 or more 6
yes Fewer than 4 8
no 4 or more 8
no Fewer than 4 10

Your program must:

  • Use input() to ask for three values:
    • The number of sandwiches.
    • Is the customer a student? The answer is yes or no.
    • The amount of money the customer has.
  • Convert the number of sandwiches and the amount of money to integers.
  • Use if, elif, and else with Boolean expressions to choose the price per sandwich. Follow the table above.
  • Calculate and store the total cost.
  • Print the price per sandwich and total cost using f-strings.
  • Compare the money the customer has with the total cost:
    • If the customer has more money than needed, calculate and print how much money will be left after buying the sandwiches.
    • If the customer has exactly enough money, print Exactly enough money.
    • If the customer does not have enough money, calculate and print how much more money they need.

Example 1

Enter the number of sandwiches: 5
Are you a student? (yes/no): yes
Enter the money you have: 35
Price per sandwich: 6
Total cost: 30
Money left: 5

Example 2

Enter the number of sandwiches: 3
Are you a student? (yes/no): yes
Enter the money you have: 24
Price per sandwich: 8
Total cost: 24
Exactly enough money

Example 3

Enter the number of sandwiches: 4
Are you a student? (yes/no): no
Enter the money you have: 30
Price per sandwich: 8
Total cost: 32
More money needed: 2

Example 4

Enter the number of sandwiches: 3
Are you a student? (yes/no): no
Enter the money you have: 40
Price per sandwich: 10
Total cost: 30
Money left: 10

Variant 9. Bottles of water

Create a file named assignment.py. Write a program that calculates the total cost of bottles of water. The program must also check if the customer has enough money.

Use this table to find the price of one bottle:

Is the customer a student? Number of bottles Price per bottle
yes 8 or more 2
yes Fewer than 8 4
no 8 or more 4
no Fewer than 8 6

Your program must:

  • Use input() to ask for three values:
    • The number of bottles.
    • Is the customer a student? The answer is yes or no.
    • The amount of money the customer has.
  • Convert the number of bottles and the amount of money to integers.
  • Use if, elif, and else with Boolean expressions to choose the price per bottle. Follow the table above.
  • Calculate and store the total cost.
  • Print the price per bottle and total cost using f-strings.
  • Compare the money the customer has with the total cost:
    • If the customer has more money than needed, calculate and print how much money will be left after buying the bottles.
    • If the customer has exactly enough money, print Exactly enough money.
    • If the customer does not have enough money, calculate and print how much more money they need.

Example 1

Enter the number of bottles: 9
Are you a student? (yes/no): yes
Enter the money you have: 20
Price per bottle: 2
Total cost: 18
Money left: 2

Example 2

Enter the number of bottles: 7
Are you a student? (yes/no): yes
Enter the money you have: 28
Price per bottle: 4
Total cost: 28
Exactly enough money

Example 3

Enter the number of bottles: 8
Are you a student? (yes/no): no
Enter the money you have: 30
Price per bottle: 4
Total cost: 32
More money needed: 2

Example 4

Enter the number of bottles: 7
Are you a student? (yes/no): no
Enter the money you have: 50
Price per bottle: 6
Total cost: 42
Money left: 8

Variant 10. Cupcakes

Create a file named assignment.py. Write a program that calculates the total cost of cupcakes. The program must also check if the customer has enough money.

Use this table to find the price of one cupcake:

Is the customer a student? Number of cupcakes Price per cupcake
yes 6 or more 3
yes Fewer than 6 5
no 6 or more 5
no Fewer than 6 7

Your program must:

  • Use input() to ask for three values:
    • The number of cupcakes.
    • Is the customer a student? The answer is yes or no.
    • The amount of money the customer has.
  • Convert the number of cupcakes and the amount of money to integers.
  • Use if, elif, and else with Boolean expressions to choose the price per cupcake. Follow the table above.
  • Calculate and store the total cost.
  • Print the price per cupcake and total cost using f-strings.
  • Compare the money the customer has with the total cost:
    • If the customer has more money than needed, calculate and print how much money will be left after buying the cupcakes.
    • If the customer has exactly enough money, print Exactly enough money.
    • If the customer does not have enough money, calculate and print how much more money they need.

Example 1

Enter the number of cupcakes: 7
Are you a student? (yes/no): yes
Enter the money you have: 25
Price per cupcake: 3
Total cost: 21
Money left: 4

Example 2

Enter the number of cupcakes: 5
Are you a student? (yes/no): yes
Enter the money you have: 25
Price per cupcake: 5
Total cost: 25
Exactly enough money

Example 3

Enter the number of cupcakes: 6
Are you a student? (yes/no): no
Enter the money you have: 25
Price per cupcake: 5
Total cost: 30
More money needed: 5

Example 4

Enter the number of cupcakes: 5
Are you a student? (yes/no): no
Enter the money you have: 40
Price per cupcake: 7
Total cost: 35
Money left: 5

Variant 11. Plant pots

Create a file named assignment.py. Write a program that calculates the total cost of plant pots. The program must also check if the customer has enough money.

Use this table to find the price of one pot:

Is the customer a student? Number of pots Price per pot
yes 5 or more 6
yes Fewer than 5 9
no 5 or more 9
no Fewer than 5 12

Your program must:

  • Use input() to ask for three values:
    • The number of pots.
    • Is the customer a student? The answer is yes or no.
    • The amount of money the customer has.
  • Convert the number of pots and the amount of money to integers.
  • Use if, elif, and else with Boolean expressions to choose the price per pot. Follow the table above.
  • Calculate and store the total cost.
  • Print the price per pot and total cost using f-strings.
  • Compare the money the customer has with the total cost:
    • If the customer has more money than needed, calculate and print how much money will be left after buying the pots.
    • If the customer has exactly enough money, print Exactly enough money.
    • If the customer does not have enough money, calculate and print how much more money they need.

Example 1

Enter the number of pots: 6
Are you a student? (yes/no): yes
Enter the money you have: 40
Price per pot: 6
Total cost: 36
Money left: 4

Example 2

Enter the number of pots: 4
Are you a student? (yes/no): yes
Enter the money you have: 36
Price per pot: 9
Total cost: 36
Exactly enough money

Example 3

Enter the number of pots: 5
Are you a student? (yes/no): no
Enter the money you have: 40
Price per pot: 9
Total cost: 45
More money needed: 5

Example 4

Enter the number of pots: 4
Are you a student? (yes/no): no
Enter the money you have: 50
Price per pot: 12
Total cost: 48
Money left: 2

Variant 12. Zoo tickets

Create a file named assignment.py. Write a program that calculates the total cost of zoo tickets. The program must also check if the customer has enough money.

Use this table to find the price of one ticket:

Is the customer a student? Number of tickets Price per ticket
yes 8 or more 7
yes Fewer than 8 10
no 8 or more 10
no Fewer than 8 13

Your program must:

  • Use input() to ask for three values:
    • The number of tickets.
    • Is the customer a student? The answer is yes or no.
    • The amount of money the customer has.
  • Convert the number of tickets and the amount of money to integers.
  • Use if, elif, and else with Boolean expressions to choose the price per ticket. Follow the table above.
  • Calculate and store the total cost.
  • Print the price per ticket and total cost using f-strings.
  • Compare the money the customer has with the total cost:
    • If the customer has more money than needed, calculate and print how much money will be left after buying the tickets.
    • If the customer has exactly enough money, print Exactly enough money.
    • If the customer does not have enough money, calculate and print how much more money they need.

Example 1

Enter the number of tickets: 9
Are you a student? (yes/no): yes
Enter the money you have: 70
Price per ticket: 7
Total cost: 63
Money left: 7

Example 2

Enter the number of tickets: 7
Are you a student? (yes/no): yes
Enter the money you have: 70
Price per ticket: 10
Total cost: 70
Exactly enough money

Example 3

Enter the number of tickets: 8
Are you a student? (yes/no): no
Enter the money you have: 75
Price per ticket: 10
Total cost: 80
More money needed: 5

Example 4

Enter the number of tickets: 7
Are you a student? (yes/no): no
Enter the money you have: 100
Price per ticket: 13
Total cost: 91
Money left: 9