Input and Output

  1. Write code to print Hello, World
    Use the print() function, and remember that strings are surrounded by double-quotes or single-quotes.
  1. Write code to print

    Hello

    World

    using 2 print statements.

    Call print() twice, on two consecutive lines.
  1. Write code to print

    Hello

    leaving the cursor on the same line.

    You have to use the optional parameter, end, in the print statement.
  1. Assume you have a variable ranking set to some integer value. Write a line of code to print the value of ranking.
    print() evaluates each variable or expression before printing it.
  1. Assume you have two variables ranking and average set to some values. Write a line of code to print the values with a single space between.
    The comma in print('x', 'y') will automatically insert a space between the two values
  1. Assume you have two variables start and interval. Write a line of code to print the sum of the two values.
    You can put expressions, like x + y into a print statement, too.
  1. Assume you have a variable ranking set to some integer value. Write a line of code to print Ranking: followed by the value that ranking refers to. Note that there should be one space between the : and the value. E.g., if ranking was 7, the output would be Ranking: 7.
    Remember, the comma in a print adds a space, so be careful!
  1. Assume you have a variable name set to a student’s name, and a variable score set to the score the student got on the last quiz. Write a line of code to print out the student’s name and the student’s score, in the following format. Name: Joe McDonald Score: 7 where the student’s name is Joe McDonald and the student’s score is 7.
    You can pass as many parameters as you want to print, separated by commas.
  1. Write code to read in a string value from the user, storing the result in a variable name.
    Use input(). You do NOT have to convert the result to a string, because input() returns a string.
  1. Write code to prompt the user for a score, reading in the score into a variable score. The type of score should be a float.
    Use input(). You have to convert the result to a float, because input() returns a string.
Next Section - Expressions