Input and Output¶
-
Write code to print
Hello, World
Use the print() function, and remember that strings are surrounded by double-quotes or single-quotes.
-
Write code to print
Hello
World
using 2 print statements.
Callprint()
twice, on two consecutive lines.
-
Write code to print
Hello
leaving the cursor on the same line.
You have to use the optional parameter,end
, in the print statement.
-
Assume you have a variable
ranking
set to some integer value. Write a line of code to print the value ofranking
.print()
evaluates each variable or expression before printing it.
-
Assume you have two variables
ranking
andaverage
set to some values. Write a line of code to print the values with a single space between.The comma inprint('x', 'y')
will automatically insert a space between the two values
-
Assume you have two variables
start
andinterval
. Write a line of code to print the sum of the two values.You can put expressions, likex + y
into aprint
statement, too.
-
Assume you have a variable
ranking
set to some integer value. Write a line of code to printRanking:
followed by the value thatranking
refers to. Note that there should be one space between the:
and the value. E.g., ifranking
was 7, the output would beRanking: 7
.Remember, the comma in aprint
adds a space, so be careful!
-
Assume you have a variable
name
set to a student’s name, and a variablescore
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 toprint
, separated by commas.
-
Write code to read in a string value from the user, storing the result in a variable
name
.Useinput()
. You do NOT have to convert the result to a string, becauseinput()
returns a string.
-
Write code to prompt the user for a score, reading in the score into a variable
score
. The type of score should be afloat
.Useinput()
. You have to convert the result to a float, becauseinput()
returns a string.