Input and Output¶
-
Write code to print
Hello, WorldUse the print() function, and remember that strings are surrounded by double-quotes or single-quotes.
-
Write code to print
HelloWorldusing 2 print statements.
Callprint()twice, on two consecutive lines.
-
Write code to print
Helloleaving the cursor on the same line.
You have to use the optional parameter,end, in the print statement.
-
Assume you have a variable
rankingset 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
rankingandaverageset 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
startandinterval. Write a line of code to print the sum of the two values.You can put expressions, likex + yinto aprintstatement, too.
-
Assume you have a variable
rankingset to some integer value. Write a line of code to printRanking:followed by the value thatrankingrefers to. Note that there should be one space between the:and the value. E.g., ifrankingwas 7, the output would beRanking: 7.Remember, the comma in aprintadds a space, so be careful!
-
Assume you have a variable
nameset to a student’s name, and a variablescoreset 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.