Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 2, Problem 4D
Explanation of Solution
a)
#Executes till the length of the list
for i in range(5):
#Multiply the value of i with i
print(i + i)
Explanation:
...Explanation of Solution
b)
#List holds the values
for d in [3,1,4,1,5]:
#Printing the values of d
print(d, end=" ")
...
Explanation of Solution
c)
#Traverse till the length of the list
for i in range(4):
#Print hello 4 times
print("Hello")
Explanation:
In the a...
Explanation of Solution
d)
#Traverse till the length of the list
for i in range(6):
#Print the values of "i" and "2**i"
print(i, 2**i)
Explanation:
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
/(8).
a) Give an example of a string in the language of (0*10*)+.
b) Give an example of a string that is not in the language of (0*10*)*.
Q5/ write a program to compute the value of R from X,Y and Z values which are X=[0,1,2......9], Y=
[2,4,6,.,20], and Z=(1,3,5,...,19]. Print the values of X,Y,Z, and R as adjacent columns.
R = √A²+B²+C²
X
√x² + y² +2²
A =
.
B=√36X* +9Y²+252²
T
C = √9+sin³Y+Z
MATLAB
Chapter 2 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
Ch. 2 - Prob. 1TFCh. 2 - Prob. 2TFCh. 2 - Prob. 3TFCh. 2 - Prob. 4TFCh. 2 - Prob. 5TFCh. 2 - Prob. 6TFCh. 2 - Prob. 7TFCh. 2 - Prob. 8TFCh. 2 - Prob. 9TFCh. 2 - Prob. 10TF
Ch. 2 - Prob. 1MCCh. 2 - Prob. 2MCCh. 2 - Prob. 3MCCh. 2 - Prob. 4MCCh. 2 - Prob. 5MCCh. 2 - Prob. 6MCCh. 2 - Prob. 7MCCh. 2 - Prob. 8MCCh. 2 - Prob. 9MCCh. 2 - Prob. 10MCCh. 2 - Prob. 1DCh. 2 - Prob. 3DCh. 2 - Prob. 4DCh. 2 - Prob. 5DCh. 2 - Prob. 6DCh. 2 - Prob. 7DCh. 2 - Prob. 1PECh. 2 - Prob. 2PECh. 2 - Prob. 3PECh. 2 - Prob. 4PECh. 2 - Prob. 5PECh. 2 - Prob. 6PECh. 2 - Prob. 7PECh. 2 - Prob. 8PECh. 2 - Prob. 9PECh. 2 - Prob. 10PECh. 2 - Prob. 11PECh. 2 - Prob. 12PE
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- [Fish Tank] You play with a clown fish that has an initial size so. The fish can eat other fish in a tank organized in m columns and n rows. The fish at column i and row j has a positive size si,j. When your fish eats another fish, it grows by that amount. For example, if your clown fish has a size of 10 and eats a fish of size 5, it becomes of size 15. You cannot eat a fish that is bigger than your size. The game starts by eating any fish in the first (left-most) column that is not bigger than yours. After that, you advance one column at a time by moving right. You have only three allowed moves. You either stay at the same row, move one row higher or one row lower. You will always move to the right. Thus, you will make exactly m moves to advance from left to right. Your goal is to exit the fish tank from the right with the biggest possible size. The figure below shows an example with the best answer highlighted. In this case, the final fish size is 71 (10+8+7+24+22). You are required…arrow_forwardOutput the information as a formatted histogram. Each name is right justified with a width of 20. Ex: Jane Austen ****** Charles Dickens ******************** Ernest Hemingway ********* Jack Kerouac ********************** F. Scott Fitzgerald ******** Mary Shelley ******* Charlotte Bronte ***** Mark Twain *********** Agatha Christie ************************************************************************* Ian Flemming ************** J.K. Rowling ************** Stephen King ****************************************************** Oscar Wilde *arrow_forwardPlease explain why the answer is T.arrow_forward
- /*code Kth Largest Factor A positive integer d is said to be a factor of another positive integer N if when N is divided by d, the remainder obtained is zero. For example, for number 12, there are 6 factors 1, 2, 3, 4, 6, 12. Every positive integer k has at least two factors, 1 and the number k itself.Given two positive integers N and k, write a program to print the kth largest factor of N. Input Format: The input is a comma-separated list of positive integer pairs (N, k). Output Format: The kth highest factor of N. If N does not have k factors, the output should be 1. Constraints: 1<N<10000000000 1<k<600. You can assume that N will have no prime factors which are larger than 13..arrow_forwardComplete the function ratio_similarity, which computes the ratio of "similarity" between two non-empty strings. The ratio is computed as follows: 2 (the number of matches of characters) / (total number of characters in both strings) The matches are determined in pairwise fashion. For example, consider the strings abcdef and abdce. The three characters at indexes 0, 1 and 4 match. Therefore, the similarity ratio is 2 * 3/(6 + 5) = 0.5454 .... Examples: Function Call string_similarity('abcdef', 'abdce') string_similarity('dragon', 'flagon') string_similarity('stony', 'stony') string_similarity('Stony Brook University', 'WolfieNet Secure') string_similarity('yabba dabba doo', 'bippity boppity boo') string_similarity('Wolfie the Seawolf', "What's...a Seawolf?") [ ] Return Value 3 4 5 # Test cases 6 print (string_similarity('abcdef', 'abdce')) 7 print (string_similarity('dragon' 1 'flagon')) 'stony')) 0.5454545454545454 0.6666666666666666 1.0 0.0 0.058823529411764705 0.4864864864864865 1…arrow_forward7. We usually write numbers in decimal form (or base 10), meaning numbers are composed using 10 different "digits" {0,1,.9). Sometimes though it is useful to write numbers in hexadecimal or base 16. Now there are 16 distinct digits that can be used to form numbers: {0,1,..,9,A,B,C,D,E,F}. So, for example, a 3 digit hexadecimal number might be 3B8. (a) How many 2-digit hexadecimals are there in which the first digit is E or F? Explain your answer in terms of the additive principle (using either events or sets). (b) Explain why your answer to the previous part is correct in terms of the multiplicative principle (using either events or sets). Why do both the additive and multiplicative principles give you the same answer? (c) How many 3-digit hexadecimals start with a letter (A-F) and end with a numeral (0-9)? Explain. (d) How many 3-digit hexadecimals start with a letter (A-F) or end with a numeral (0-9) (or both)? Explain.arrow_forward
- Write a statement that calls the recursive function backwards_alphabet() with input starting_letter.Sample output with input: 'f'f e d c b aarrow_forwardWrite a recursive function that takes as a parameter a nonnegative integer and generates the following pattern of stars. If the nonnegative integer is 4, the pattern generated is as follows: **** *** ** * * ** *** **** Also, write a program that prompts the user to enter the number of lines in the pattern and uses the recursive function to generate the pattern. For example, specifying 4 as the number of lines generates the preceding pattern.arrow_forward(Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.arrow_forward
- Consider the following expression using Racket: (= (string-length "hello world") (/ (+ 10 10) 5) ) 1) What data type does the above expression return when evaluated? a.) Boolean, b.) string, c.) Integer, d.) Real, e.) Complex 2) What is the first operation performed in the evaluation of the expression above? a.) The equality, ‘=’, is performed first. b.) The division, ‘/’, is performed first. c.) The addition, ‘+’, is performed first. d.) The string-length operation is performed first. e.) The first operation performed depends on the operating system in use.arrow_forwarda) Write a recursive method that calculates the following series: F(n)= (n1+i)ni=1*(n2+i)n/2i=1*(n4+i)n/4i=1*(n8+i)n/8i=1*....*2 b) Write the recurrence expression T(n).arrow_forwardPython only** Use recursive function* Define countBetween with 2 parameters Use def to define countBetween with 2 parameters thas two parameters: a starting number and an ending number, and counts up (i.e., prints consecutive integers) from the starting number to the ending number. If the numbers are the same, it just prints that number; if the ending number is lower than the starting number, it prints nothing. Do not use any kind of loop Within the definition of countBetween with 2 parameters, do not use any kind of loop. Call countBetween Within the definition of countBetween with 2 parameters, call countBetween in at least one place. Python only** Use recursive function* Define countThereAndBack with 2 parameters Use def to define countThereAndBack with 2 parameters after reaching the ending number, it also counts back down to the starting number. It accepts the same two parameters defining starting and ending numbers it should print nothing if the starting number is…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Introduction to Operators in C; Author: Neso Academy;https://www.youtube.com/watch?v=50Pb27JoUrw;License: Standard YouTube License, CC-BY