Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Assignment The purpose of this assignment is to write a program that computes and saves to file the Hailstone Numbers for all integers starting

The Assignment The purpose of this assignment is to write a program that computes and saves to file the Hailstone Numbers for all integers starting from 1 up through and including 25. In the JES environment, type in the following program code, except for the comments in the bodies of the functions, and save it in your Python folder with Lab1.py as the filename. Where you see my name, replace it with your own name. # Lab 1 def Hailstones (N): # Your code for the Hailstones function # goes here. def Main(): # Your main program code # goes here. return Task #1 Complete the Hailstones function so that for any input value in N, it computes and returns a list containing all Hailstone values starting at N and continuing until 1 is reached. That is: Hailstones(1) should return [1] Hailstones(2) should return [2, 1] Hailstones(3) should return [3, 10, 5, 16, 8, 4, 2, 1] Hailstones(4) should return [4, 2, 1] Hailstones(5) should return [5, 16, 8, 4, 2, 1] etc. When you finish writing the Hailstones function, save your file and then click the Load Program button. Fix any syntax errors. Every time you change the program you must re-save the source code (File-Save, or CS on Windows, or S on Mac), then click the Load Program button. Be very careful about indentation (please use exactly four spaces per level throughout the program) and capitalization (for example, variables frog, FROG, and Frog are all different). Places where errors can creep in are through missing or extra quotes, parentheses, colons, commas, etc., along with incorrect indentation levels. Test your function in the interactive area of Python, and make certain it works before proceeding. Task #2 Now we need to complete the main program, which is to call the Hailstones function for all values from 1 through 25 (inclusive) and write the results to a text file called Hailstones.txt. The sequence of steps for you to complete in Main is as follows: Step 1: Using pickAFolder, ask the user for the name of the folder to store the results and save that string in a variable. Step 2: Create a file name variable by combining the result of step 1 with the string "Hailstones.txt". Step 3: Open the file for writing using the file name generated in step 2. Step 4: For each integer from 1 through 25, get the appropriate Hailstone sequence for that integer, convert the resulting list to a string, and write the string to the file. Step 5: Close the file. Step 6: Return If everything works correctly when you type Main() followed by R, you will get asked for the name of the destination folder, and then the program will run to completion. In the specified folder there will now be a Hailstones.txt file, where the first few lines of that 25-line file will be: [1] [2, 1] [3, 10, 5, 16, 8, 4, 2, 1] [4, 2, 1] [5, 16, 8, 4, 2, 1] If the file does not contain the correct information, debug your program and run it again. Repeat the process until the resulting file does contain the correct information.

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

Beginning VB.NET Databases

Authors: Thearon Willis

1st Edition

1594864217, 978-1594864216

More Books

Students also viewed these Databases questions