Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Python! Thanks Hint 1 : there are (at least) two approaches you can take: create a list of strings of numbers (e.g. ['1','3', '5','4','2']

Using Python! Thanks

image text in transcribedHint 1: there are (at least) two approaches you can take: create a list of strings of numbers (e.g. ['1','3', '5','4','2'] and then turn that into a string (join method), or build the output string directly. In the second case you may first want to build the string without spaces ('13542'), and then modify the code to also generate the spaces. Hint 2: Whatever you do, do some small examples, n = 5 and n=6 by hand. Where do you start? Right, with the largest number, not with 1. Hint 3: to get from int to str use the str() function.

4. (First printings, 15pt) If you've ever looked at the copyright of a book (remember, heavy thingy with pages you had to turn?) you may have seen number sequences like 13 579 108 642 What this means is that the book is a first printing (of a first edition, for example). When the publisher reprints the book, they just drop the 1, and the smallest number, 2 at the end, tells you that you have a second printing, and so on. Why order the numbers in this alternating fashion? In this way, the number sequence remains nicely centered (this made more sense when typesetting stil literally meant that type was being set, but the custom remained). Write a program alternate(n) which creates and returns a string containing the numbers from 1 through n in this alternating order. Below are some test-runs. There are two restrictions: do not use slicing (so no s1::2] allowed), though indexing is fine (si], etc.); and only use a single loop which adds one number in each iteration. Below are two hints if you want partial spoilers. Python 3.5.2 Shell Eile Edit Shell Debug Options Window Help >>>alternate (5) 1 3 5 4 2' >>>alternate (6) '1 3 5 6 4 2 >>>alternate (10) '1 3 5 7 9 10 8 6 4 2 >alternate (20) '1 3 5 7 9 11 13 15 17 19 20 18 16 14 12 10 8 6 4 2 Ln: 21 Col: 13

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

Demystifying Databases A Hands On Guide For Database Management

Authors: Shiva Sukula

1st Edition

8170005345, 978-8170005346

More Books

Students also viewed these Databases questions

Question

What are the attributes of a technical decision?

Answered: 1 week ago

Question

How do the two components of this theory work together?

Answered: 1 week ago