Exercises

Unless specified otherwise, use IPython sessions for each exercise.

  1. 2.1 (What does this code do?) Create the variables x = 2 and y = 3, then determine what each of the following statements displays:

    1. print('x =', x)

    2. print('Value of', x, '+', x, 'is', (x + x))

    3. print('x =')

    4. print((x + y), 'x =', (y + x))

  2. 2.2 (What’s wrong with this code?) The following code should read an integer into the variable rating:

    rating = input('Enter an integer rating between 1 and 10')
    
  3. 2.3 (Fill in the missing code) Replace *** in the following code with a statement that will print a message like 'Congratulations! Your grade of 91 earns you an A in this course'. Your statement should print the value stored in the variable grade:

    if grade >= 90 ...

Get Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and The Cloud now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.