Python Programming: An Introduction to Computer Science, 3rd Ed.
Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
bartleby

Concept explainers

bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 3, Problem 4D

Explanation of Solution

a)

Given code segment:

#Loop from 1 to 11

for i in range(1, 11):

  #Print square of the number

  print(i * i)

Explanation:

Explanation of Solution

b)

Given code segment:

#Iterate the list

for i in [1, 3, 5, 7, 9]:

 #Print the cube of each value

 print(i, ":", i ** 3)

#print the value of i

print(i)

Explanation:

Explanation of Solution

c)

Given code segment:

#Declare required variables

x = 2

y = 10

#Loop

for j in range(0, y, x):

 #Print the value of j

 print(j, end = "")

 #Print the value of x+y

 print(x + y)

#print done

print("done")

Explanation:

Explanation of Solution

d)

Given code segment:

#Declare required variables

ans = 0

#Loop

for i in range(1, 11):

 #Calculate the value of ans

 ans = ans + i * i

 #Print the value of i

 print(i)

#print the value of ans

print(ans)

Explanation:

Blurred answer
Students have asked these similar questions
ISP- Java  Write a program that will output a right triangle based on user specified input height (int) and specified input symbol (char). The first line will have one user-specified character, such as % or *. Each subsequent line will have one additional user-specified character until the number in the triangle's base reaches specified input height. Output a space after each user-specified character, including after the line's last user-specified character. Hint: Use a nested for loop. Ex: If the input is: Enter a character: * Enter triangle height: 8 the output is: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Task 9 Write Python code of a program that reads an integer, and prints the integer if it is a multiple of NEITHER 2 NOR 5. For example, 1, 3, 7, 9, 11, 13, 17, 19, 21, 23, 27, 29, 31, 33, 37, 39 ... hint(1): use the modulus (%) operator for checking the divisibility hint(2): You can consider the number to be an integer !%3%===== Example01: Input: 3 Output: 3
Write in Java: Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0       Output x % 2 (remainder is either 0 or 1)       x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string. Ex: If the input is: 6 the output is: 110 Your program must define and call the following two methods. The method integerToReverseBinary() should return a string of 1's and 0's representing the integer in binary (in reverse). The method reverseString() should return a string representing the input string in reverse. public static String integerToReverseBinary(int integerValue)public static String reverseString(String inputString) LabProgram.java: import java.util.Scanner; public class LabProgram {/* Define your method here */ public static void main(String[] args) {/* Type your code…
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Computational Software for Intelligent System Design; Author: Cadence Design Systems;https://www.youtube.com/watch?v=dLXZ6bM--j0;License: Standard Youtube License