Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
def hailstone(n):
h.append(int(n))
if n == 1:
return h
while n != 1:
if n % 2 == 0:
return hailstone(int(n/2))
else:
return hailstone(int(3*n + 1))
y=int(input("N: "))
if y <= 0:
print("N must be positive!")
else:
print("Hailstone sequences for 1 to " + str(y) + ": ")
m=0;
i=1
for x in range(1, y+1):
n = i
h = []
h = hailstone(n)
print(*h)
s=len(h)
if s > m:
m=s
flag=n
i=i+1
print("First longest sequence found in n =", + flag )
What if I still want the comma between each number. without any square brackets in frint and end.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps
Knowledge Booster
Similar questions
- What is the value of sum?int w = 5;int sum = 0;for (int r = 1; r <= w; r++)for (int s = r; s <= w; s++)sum = sum + s;arrow_forwarddef accuracy(y, y_hat): # TODO 8.1 total_correct = # TODO 8.2 total_samples = print(f"Accuracy ratio: {total_correct}/{total_samples}") # TODO 8.3 return def TEST_accuracy(): dummy_y = np.ones([100, 1]) dummy_y_hat = np.ones([100, 1]) dummy_y_hat[90:] = -1 dummy_acc = accuracy(dummy_y_hat, dummy_y) print(f"Accuracy is: {dummy_acc}") todo_check([ (dummy_acc == .9,"Incorrect accuracy value") ]) TEST_accuracy() garbage_collect(['TEST_accuracy'])arrow_forwardWhat will the final values of count1 and count2 be in terms of n? assume that n is a power of 2 of the form 2^r.arrow_forward
- Correct code to output the following: 0 2 4 6 8 10 12 14 16 18 CODE: int[] numbers = new int[10]; for(int i=0; i < numbers.length; ++i) numbers[i] = i * 2; for(int i=0; i < numbers.length; i++) System.out.print(numbers[++i] + " "); System.out.println();arrow_forwardFind the errors in this code: double gpa[] = {2.2, 3.8, 4.0, 3.6, 1.7, 2.8}; int countSuper = 0; // number of students whose GPA >= 3.5 for (int count = 0; count < 6; count++){ if(gpa[count] >= 3.5){ System.out.print(”\n You are super!”); } countSuper++; } System.out.print(”\n Number of super students is: ”+ countSuper);arrow_forwardAnalyze errorIf (x < 100) && (x> 10)System.out.println(“x” is between 10 and 100”);arrow_forward
- Exercise 1Write a Java method random that generates and returns a random number between 14 and 59(using SecureRandom). Test your method several times using a main functionarrow_forwardPython Turtle: How do I fix the code to make it generate lakes as bigger random dots, and mountains as a separate color (gray) from the grass area? (Big error: lake generates as entire circle inside land, want it generating like mountains).AKA: How do I separate each of the values to generate on its own without conflicting eachother. import turtleocean = "#000066"sand = "#ffff66"grass = "#00cc00"lake = "#0066ff"mountain = [[-60, 115], [-65, 200], [-10, 145], [-30, 70], [50, 115], [100, 150], [70, 200], [30, 70], [10, 180], [-10, 220]]def draw_circle(radius, line_color, fill_color): my_turtle.color(line_color) my_turtle.fillcolor(fill_color) my_turtle.begin_fill() my_turtle.circle(radius) my_turtle.end_fill()def move_turtle(x, y): my_turtle.penup() my_turtle.goto(x, y) my_turtle.pendown()num_cuts = int(input("How many rivers do you want on your Island? ")) screen = turtle.Screen()screen.bgcolor(ocean)screen.title("Island Generator")my_turtle =…arrow_forwardFind the values of n and m to solve this puzzle int n = ? int m = ? int t = 76; int s = 0; char *msg = "Do you like spaghetti? Try some spaghetti! It's good, right?\n" "What, you prefer structured loops? How mundane.\n"; goto LTOP; LEND: failure(msg); LOM1: n = (n<<2) - n + 1; LCHK: if(s == t && m == t){ goto LAFT; } s++; goto LTOP; LOC1: if(n & 1){ goto LOM1; } goto LEM1; LTOP: if(!(n>1)){ goto LEND; } goto LOC1; LEM1: n = n >> 1; goto LCHK; LAFT: return;arrow_forward
- def hailstone(n): h.append(int(n)) if n == 1: return h while n != 1: if n % 2 == 0: return hailstone(int(n/2)) else: return hailstone(int(3*n + 1))y=int(input("N: "))if y <= 0: print("N must be positive!")else: print("Hailstone sequences for 1 to " + str(y) + ":") m=0; i=1 for x in range(1, y+1): n = i h = [] h = hailstone(n) print(h) s=len(h) if s > m: m=s flag=n i=i+1 print("First longest sequence found in n =", + flag ) If i don't one the output have the square braket? How can I fix this code? Can you pleasw help me?arrow_forwardJAVA Language: Transpose Rotate. Question: Modify Transpose.encode() so that it uses a rotation instead of a reversal. That is, a word like “hello” should be encoded as “ohell” with a rotation of one character. (Hint: use a loop to append the letters into a new string) import java.util.*; public class TestTranspose { public static void main(String[] args) { String plain = "this is the secret message"; // Here's the message Transpose transpose = new Transpose(); String secret = transpose.encrypt(plain); System.out.println("\n ********* Transpose Cipher Encryption *********"); System.out.println("PlainText: " + plain); // Display the results System.out.println("Encrypted: " + secret); System.out.println("Decrypted: " + transpose.decrypt(secret));// Decrypt } } abstract class Cipher { public String encrypt(String s) { StringBuffer result = new…arrow_forwarddef hailstone(n): h.append(int(n)) if n == 1: return h while n != 1: if n % 2 == 0: return hailstone(int(n/2)) else: return hailstone(int(3*n + 1))y=int(input("N: "))if y <= 0: print("N must be positive!")else: print("Hailstone sequences for 1 to " + str(y) + ": ") m=0; i=1 for x in range(1, y+1): n = i h = [] h = hailstone(n) print(*h) print(",") s=len(h) if s > m: m=s flag=n i=i+1 print("First longest sequence found in n =", + flag ) How can I fix this code if I want a comma between each number, not each line?arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY