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
Write down the output on the screen, when the following c program fragments of code are executed:
1st code
int i,sum=0;
for(i=10 ; i>0 ; i++){
sum+=i*i;
i++;
}
printf("%d\n",sum);
2. code
int a[3][3]={{1, 2, 3}, {4, 5, 6}, {7, 8 ,9}};
for (i=0 ; i<3 ; i++){
for (j=0 ; j<3 ; j++){
printf("%d ",a[j][i]);
}
printf("\n");
}
Write a program in C++ to find the area of any triangle using Heron'sFormula:
Side = (a+b+c)/2Area= sqrt (Side *(side-a) *(Side-b)*(Side-c)Note: use #include <math.h> to run/recognize the sqrt
Sample Input:Input the length of 1st side of the triangle : 5Input the length of 2nd side of the triangle : 5Input the length of 3rd side of the triangle : 5Sample Output:The area of the triangle is : 10.8253
1. a Write a regular expression for the set of binary strings where each string has at least one pair of consecutive zeros.
b. write the regular expression for the following, where sigma = (a,b): i. string of length at least 2 ii. string of length at most 2 iii. all string starting with a and ending with b iv. Even length Strings
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
- Consider the following code fragment: if x > 10:if y < 5:print("A")else:print("B")else:print("B") Which of the following code fragment is equivalent (that is, behaves exactly in the same way) as the fragment above? Select one: a.if x > 10 or y < 5:print("A")else:print("B") b.if x > 10 and y < 5:print("A")else:print("B") c.if x > 10 or y < 5:print("B")else:print("A") d.if x > 10 and y < 5:print("B")else:print("A")arrow_forwardWrite a program in C++ and takes the string from the user and only use character arrays. SAMPLE OUTPUT: Input: I am a student of PF in FAST-NU. Output: I am a student of PF in FAST-NU Hint: Words are separated by spaces.arrow_forwardWhat will be the output of the following C snippet? int x = -3, i = -1;do {x = x++;i++;} while (i != 4);printf("%d\n", ++x); Select one: a. 2 b. -2 c. -1 d. 3arrow_forward
- What is the exact output (in C++) of the following pseudocode segment? FOR I from 1 to 4 FOR J from 1 to 4 PRINT((J-I) + "\t") ENDFOR PRINTLINE() ENDFORarrow_forwardLoops question. Write a C program that reads an integer k from the user and then prints the multiples of 1 up to k, the multiples of 2 up to k/2, etc. For k = 10, the printout would be 1,2,3,4,5,6,7,8,9,10, 2,4,6,8,10 3,6,9 4,8 5,10,arrow_forwardWrite a program that generates 1,000 lowercase letters randomly, counts the occurrence of each letter, and displays a histogram for the occurrences, as shown in Figure 10.16a.arrow_forward
- Given a number n, identify and print which in the given set of numbers are factors of n. Should there be no factors listed in the set of numbers, print "I'm alone". For example, given the number 36 and the set of numbers 2, 3, 5, 7, 12. Only print the numbers which are factors of 36, which are 2, 3, 12. Input The first line contains the number n; The second line contains how many numbers there are in the set of numbers; The third line contains the set of numbers. INPUT: 36 5 2·3·5·7·12 Output The set of numbers that are factors of n separated by a new line in order of appearance. If there are none, print "I'm alone" OUTPUT: 2 3 12arrow_forwardWrite the result or output of the following program. M=5 N=2 P-M/N P=M//N P-P+N P=P+M print(" First and second value of P is:" ,P,P) print("Third and Fourth value of P is:" P,P) M-M%N P-M+N print("M=",M,"N="N,"P-".P)arrow_forwardWrite a code segment to read in temperatures until -1 and calculate the average. JAVAarrow_forward
- Question 2. Write a Program to replace all 0’s with 1 in a given integer. Given an integer as an input, all the 0’s in the number has to be replaced with 1. For example, consider the following number Input: 102405Output: 112415 Input: 56004Output: 56114 DM your S.arrow_forward1- Given an input consisting of one or more sets of strings, followed by a final line containing only the value 0. Each set starts with a line containing an integer, k, which is the number of strings in the set, followed by k strings, one per line. For example, if your input is: Input = { "7", "Bo", "Jean", "Marybeth", "Kevin", "Claude", "William", "Pat", "6", "Jim", "Ben", "Annabelle", "Zoe", "Joey", "Frederick", "5", "John", "Billy", "Fran", "Stant", "Cece", "2", "Jones", "Bibi", "0" } Your output should look like that: 2- Given the sorted input from question 1, write a new code such that the shorter strings go on the top and bottom and the longer strings sit in the middle. In other words, each pair of names belongs on opposite ends of the list, and the first name in the pair is always in the top part of the list. For example, in Set 1 below, Bob and Joe are the first pair, Jean and Kevin the second pair, etc. Your output should look like the sample below.…arrow_forwardWhat do these code fragments print?(a) int n=1, m= -1; if(n < -m) cout<<n; else cout<<m; (b) int x=0, y=1; if(abs(x-y)<1) cout<<x; else cout<<y;arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Introduction to Operators in C; Author: Neso Academy;https://www.youtube.com/watch?v=50Pb27JoUrw;License: Standard YouTube License, CC-BY