Docsity

Python Session 2 assignments, Exercises of Computer science

Toggle sidebar
bg1
Session 2: Assignments
1. Read the given handout and answer the following questions:
- How to check a variable’s type?
- In what cases, you will get SyntaxError from the compiler telling you
that some of your variables have invalid names? Can you give 3
different examples of invalid names?
2. Write a program that calculates the area of a circle. The circle radius is
entered by users
Expected screen output:
# This one is fine
# This one is a little bit better
3. Write a program that converts Celsius (0C) into Fahrenheit (0F)
Expected screen output:
# This one is fine
# This one is a little bit better
4. Bacteria B replicates itself each 2 minutes, write a program that asks users
to enter two numbers: the initial B bacteria number and a period of time
(in minutes). Calculate and print out the total number of B bacteria after
this period.
B B
B B B B
B B B BBB B B
2 minutes
2 minutes
pf3

Partial preview of the text

Download Python Session 2 assignments and more Exercises Computer science in PDF only on Docsity!

Session 2: Assignments

  1. Read the given handout and answer the following questions:
    • How to check a variable’s type?
    • In what cases, you will get SyntaxError from the compiler telling you that some of your variables have invalid names? Can you give 3 different examples of invalid names?
  2. Write a program that calculates the area of a circle. The circle radius is entered by users Expected screen output:

This one is fine # This one is a little bit better

  1. Write a program that converts Celsius (^0 C) into Fahrenheit (^0 F) Expected screen output:

This one is fine # This one is a little bit better

  1. Bacteria B replicates itself each 2 minutes, write a program that asks users to enter two numbers: the initial B bacteria number and a period of time (in minutes). Calculate and print out the total number of B bacteria after this period. B B

B B B B

B B B B B B B B

2 minutes

2 minutes

Expected screen output:

or:

  1. In Happy Farm, there are initially a couple of rabbits (female and male). This couple of the rabbits reproduces a new couple of rabbits each month. Each newborn rabbit couple becomes mature in one month and then gives a life to a new rabbit couple each month after. Write a program that calculates the number of couples of rabbit after 4 months.

Month 0

Month 1

Month 2

Month 3

Birth

Birth

Grow

Grow

Birth

Birth

Hint: Google “ Fibonacci Rabbits”