Open In Colab

Python Basic Exercises

Question 1

Predict the output of the following code blocks? Run them in Colab to check if your predictions were correct?

Note: You might have to look on the internet for the meaning of some symbols (such as / and %)

Question 2

Modify the above code to print ‘Hello Hello Hello Hello Batman’ when the name is ‘Batman.’

Modify the code to respond to Robin instead of Batman.

Question 3

The following code has a few bugs; fix them!

Question 4

  1. What is the number in the 4th position in the array?
  1. What is the last number in the array?
  1. What are the first 3 values?
  1. What are the values from the 4th to the 10th position? (This should include the numbers at the 4th and 10th positions.)
  1. What are the values in the list greater than 500?
  1. Use the 'hidden' numpy functions max(), min(), mean() and std() to find the maximum, minimum, mean and standard deviation of the values of the numpy array.
  1. Make all the numbers less than 500 equal to zero!
  1. What are the values in the list greater than 500 and less than 1000?

Note