Application#
How to Submit#
Your answers to this chapter’s application questions should be added to the notebook template.
Google Colab link (ND users only)
Submit the Colab link on Canvas for the assignment submission.
Application Questions#
Q1: Write a program that asks a user to enter a color value and returns an output message comparing that value with your favorite color. This program will use a combination of the input() function, comparison operators, and if-then-else logic. Answer to this question includes program + comments that document process and explain your code.
Sample output for this program:
Your favorite color: green
My age: blue
We don't have the same favorite color.
Q2: Write a program that lets the user play a guessing game.
First, your program should set a number as the “correct answer”
Then, your program will ask the user to guess a number
Your program should give a message indicating whether the user’s guess is correct, too high, or too low
This program will use a combination of the input() function, comparison operators, and if-then-else logic. Answer to this question includes program + comments that document process and explain your code.
Sample output for this program (for a correct answer of 7:
You guessed 13.
Q3: Return to your Q1 color guessing game program. Rewrite the program to use a whlie statement and continue until the user guesses your favorite color. This program will use a combination of the input() function, comparison operators, a while statement, and if-then-else logic. Answer to this question includes program + comments that document process and explain your code.
Q4: Write a program that lets the user play a guessing game.
First, your program should set a number as the “correct answer”
Then, your program will ask the user to guess a number
Your program should give a message indicating whether the user’s guess is correct, too high, or too low
This program will use a combination of the input() function, comparison operators, and if-then-else logic. Answer to this question includes program + comments that document process and explain your code.
Sample output for this program (for a correct answer of 7:
You guessed 13.
Q5: Given the following program:
# assign count variable
count = 1
# while loop
while count <= 5: # initial condition
print ("Python") # print statement
count = count + 1 # reassign count
# final print statement
print ("Done")
How would you modify the program to print or output the string nine (9) times and also include line numbers as part of the output? Answer to this question includes program + comments that document process and explain your code.
For example, your output might look like the following:
1 Python
2 Python
3 Python
4 Python
5 Python
6 Python
7 Python
8 Python
9 Python
IS FUN!
Q6: Let’s return to the previous question’s program. How would you modify your program to use a for loop instead of a while loop? Answer to this question includes program + comments that document process and explain your code.
As a reminder, your output might look like the following:
1 Python
2 Python
3 Python
4 Python
5 Python
6 Python
7 Python
8 Python
9 Python
IS FUN!
Q7: An earlier application question asked you to modify the program below to search for the characters q and u in the string turquoise.
# assign string variable
color = "turquoise"
# get index number of t character
index_number = color.index("t")
# show index number as part of print statement
print ("The index number for the letter t within the word " + color + " is " + index_number)
Write a program that uses a for loop to return all instances of q and u in the string, not just the first occurrence. Answer to this question includes program + comments that document process and explain your code.
Q8: Write a program that asks the user to enter three numbers: a starting value, an ending value, and an increment. Your program should then “count” based on these criteria, as shown in the sample output below. Answer to this question includes programs with a while loop and a for loop + comments that document process and explain your code.
This program counts for you.
Enter the starting value: 3
Enter the ending value: 13
Enter the increment: 2
3
5
7
9
11
13
Q9: Write a program that prints the numbers 1 through 10, except that between 7 and 8 it should print the word “happy.” Answer to this question includes programs with a while loop and a for loop + comments that document process and explain your code.
Sample output for this program:
1
2
3
4
5
6
7
happy
8
9
10