Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Page 151 P3.3 Write a program that reads an integer and prints how many digits the number has, by checking whether the number is

Python
Page 151
P3.3
Write a program that reads an integer and prints how many digits the number has, by checking whether the number is 10, 100, and so on. (Assume that all integers are less than ten billion.) If the number is negative, first multiply it by 1.
P3.5
Write a program that reads three numbers and prints increasing if they are in increasing order, decreasing if they are in decreasing order, and neither otherwise. Here, increasing means strictly increasing, with each value larger than its predecessor. The sequence 3 4 4 would not be considered increasing.
P3.9
Write a program that reads a temperature value and the letter C for Celsius or F for Fahrenheit. Print whether water is liquid, solid, or gaseous at the given temperature at sea level.
P3.12
Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and F, possibly followed by + or . Their numeric values are 4, 3, 2, 1, and 0. There is no F+ or F. A + increases the numeric value by 0.3, a decreases it by 0.3. However, an A+ has value 4.0.
Enter a letter grade: B-
The numeric value is 2.7.
P3.14Write a program that takes user input describing a playing card in the following shorthand notation:
A
Ace
2 ... 10
Card values
J
Jack
Q
Queen
K
King
D
Diamonds
H
Hearts
S
Spades
C
Clubs
Your program should print the full description of the card. For example,
Enter the card notation: QS
Queen of Spades
R4.1
Write a while loop that prints
a. All squares less than n. For example, if n is 100, print 0 1 4 9 16 25 36 49 64 81.
b. All positive numbers that are divisible by 10 and less than n. For example, if n is 100, print 10 20 30 40 50 60 70 80 90
c. All powers of two less than n. For example, if n is 100, print 1 2 4 8 16 32 64.
R4.2
Write a loop that computes
a. The sum of all even numbers between 2 and 100 (inclusive).
b. The sum of all squares between 1 and 100 (inclusive).
c. The sum of all odd numbers between a and b (inclusive).
d. The sum of all odd digits of n. (For example, if n is 32677, the sum would be 3 + 7 + 7 = 17.)
R4.4
What do these loops print?
a. for i in range(1, 10) :
print(i)
b. for i in range(1, 10, 2) :
print(i)
c. for i in range(10, 1, 1) :
print(i)
d. for i in range(10) :
print(i)
e. for i in range(1, 10) :
if i % 2 == 0 print(i)
R4.10
How many iterations do the following loops carry out?
a. for i in range(1, 11) . . .
b. for i in range(10) . . .
c. for i in range(10, 0, 1) . . .
d. for i in range(10, 11) . . .
e. for i in range(10, 0) . . .
f. for i in range(10, 11, 2) . . .
g. for i in range(10, 11, 3) . . .
R4.14
Write pseudocode for a program that reads a student record, consisting of the students first and last name, followed by a sequence of test scores and a sentinel of 1. The program should print the students average score. Then provide a trace table for this sample input:
Harry
Morgan
94
71
86
95
1
R4.19
What do the following program segments print? Find the answers by tracing the code, not by using the computer.
a. n = 1
for i in range(2, 5) :
n = n + i
print(n)
b. n = 1 / 2
i = 2
while i < 6 :
n = n + 1 / i
i = i + 1
print(i)
c. x = 1.0
y = 1.0
i = 0
while y >= 1.5 :
x = x / 2
y = x + y
i = i + 1
print(i)
Page 229
P4.1
Write programs with loops that compute
a. The sum of all even numbers between 2 and 100 (inclusive).
b. The sum of all squares between 1 and 100 (inclusive).
c. All powers of 2 from 20 up to 220.
d. The sum of all odd numbers between a and b (inclusive), where a and b are inputs.
e. The sum of all odd digits of an input. (For example, if the input is 32677, the sum would be 3 + 7 + 7 = 17.)
P4.3
Write programs that read a line of input as a string and print
a. Only the uppercase letters in the string.
b. Every second letter of the string.
c. The string, with all vowels replaced by an underscore.
d. The number of digits in the string.
e. The positions of all vowels in the string.
P4.8
Write a program that reads a word and prints each character of the word on a separate line. For example, if the user provides the input "Harry", the program prints
H
a
r
r
y

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions