#1 1.1 Write a Python program with a loop that prints out a sequence of numbers as follows:151311...31-1
A simple approach with a for loop: def MyRange(start, end, step): for n in range(start, end, step): if n == 0: print -1 break else: print n return #call the function MyRange(151311, -1, -31) Hope that helps! 2010/1/31 <tutor-requ...@python.org>: > Send Tutor mailing list submissions to > tu...@python.org > > To subscribe or unsubscribe via the World Wide Web, visit > http://mail.python.org/mailman/listinfo/tutor > or, via email, send a message with subject or body 'help' to > tutor-requ...@python.org > > You can reach the person managing the list at > tutor-ow...@python.org > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Tutor digest..." > > > Today's Topics: > > 1. Re: can any one help (invincible patriot) > 2. Re: can any one help (Grigor Kolev) > 3. please help me (invincible patriot) > > > ---------------------------------------------------------------------- > > Message: 1 > Date: Sat, 30 Jan 2010 23:24:18 +0000 > From: invincible patriot <invincible_patr...@hotmail.com> > To: <grigor.ko...@gmail.com> > Cc: tutor@python.org > Subject: Re: [Tutor] can any one help > Message-ID: <col107-w13c745249b64f8355e768ae2...@phx.gbl> > Content-Type: text/plain; charset="windows-1251" > > > ???? didnt got what u replied > > > Subject: Re: [Tutor] can any one help > From: grigor.ko...@gmail.com > To: invincible_patr...@hotmail.com > CC: anand.shash...@gmail.com; tutor@python.org > Date: Sun, 31 Jan 2010 01:21:15 +0200 > > > > > > > > > > > ? 22:49 +0000 ?? 30.01.2010 (??), invincible patriot ??????: > > > ya definately, just give me the hint > > > i made a prog for the first one but it when ran, saying RESTART in active > shell > > > > > > > > > def fibn(n): > > > a,b=15,2 > > > while a>n: > > > print a, > > > a,b=a,a+b > > > fibn(-1) > > > > > > > > > whatz rong in this prog that the error is saying no break point > > > > > > > > > thanks > > > > > > From: anand.shash...@gmail.com > > Date: Sun, 31 Jan 2010 04:16:40 +0530 > > Subject: Re: [Tutor] can any one help > > To: invincible_patr...@hotmail.com > > CC: tutor@python.org > > > > I got the question. I just gave you hints, so as you can try yourself. > Also please use 'Reply all' > > > > > > On Sun, Jan 31, 2010 at 4:08 AM, invincible patriot > <invincible_patr...@hotmail.com> wrote: > > > > I want to use WHILE LOOP in the first one and in the second question > we need to take a string 'foobar' and then we should make the prog to get the > following out put > > > > > let me tel u the exact question > > > > > > > > > > > > > Write a small Python program that generates the list of all pairs of > characters c and > > > > > its doubling 2 c, where c moves through all the letters of the string > "foobar" and prints it out. > > > > > The result will look like: > > > > > [(?f?, ?ff?), (?o?, ?oo?), (?o?, ?oo?), (?b?, ?bb?), (?a?, ?aa?), > (?r?, ?rr?)] > > > > > > > > > > > > > thatz the exact 2nd question > > > > > also let me know aboutthe first one > > > > > > > > > > > > > thanks allot > > > > > > > > > > > From: anand.shash...@gmail.com > > > > > > > > Date: Sun, 31 Jan 2010 04:05:09 +0530 > > > > > > > Subject: Re: [Tutor] can any one help > > To: invincible_patr...@hotmail.com > > CC: tutor@python.org > > > > > > > > > > > > > > > > Tips: > > > > 1. > > range can be stepped down in reverse order > > ex -> > > >>> range(10, 1, -2) > > [10, 8, 6, 4, 2] > > > > 2. > > you can directly get chars of string. > > ex -> > > >>> [i for i in 'foobar'] > > ['f', 'o', 'o', 'b', 'a', 'r'] > > also > > >>> 2 * 'f' > > 'ff' > > > > > > > > > > On Sun, Jan 31, 2010 at 3:56 AM, Shashwat Anand > <anand.shash...@gmail.com> wrote: > > > seems like homework ;) > > Can you paste your approach here ? > > > > > > > > > > > > > > > > > > On Sun, Jan 31, 2010 at 3:03 AM, invincible patriot > <invincible_patr...@hotmail.com> wrote: > > > > > > > > > > > > > > > > > > > > > > > hi > > > > > > > > > i am stuck in few tasks can some one help me in that > > > > > > > > > here are first few tasks > > > > > > > > > > > > > > > > > > > > > 1 > > > > > > > > > how can i print the following series, using a loop > > > > > > > > > 15 > > > > > > > > > 13 > > > > > > > > > 11 > > > > > > > > > ... > > > > > > > > > 3 > > > > > > > > > 1 > > > > > > > > > -1 > > > > > > > > > ======== > > > > > > > > > 2 > > > > > > > > > Write a small Python program that generates the list of all > pairs of characters c and > > > > > > > > > its doubling 2 c, where c moves through all the letters of the > string "foobar" and prints it out. > > > > > > > > > The result will look like: > > > > > > > > > [(?f?, ?ff?), (?o?, ?oo?), (?o?, ?oo?), (?b?, ?bb?), (?a?, > ?aa?), (?r?, ?rr?)] > > > > > > > > > > > > > > > > > > > > > please help me out in these two tasks > > > > > > > > > > > > > > > > > > > > > > > > > > > Hotmail: Trusted email with powerful SPAM protection. Sign up > now. > > > > > > > > > > > > > > > > > > > > > _______________________________________________ > > Tutor maillist - tu...@python.org > > To unsubscribe or change subscription options: > > http://mail.python.org/mailman/listinfo/tutor > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > Hotmail: Trusted email with powerful SPAM protection. Sign up now. > > > > > > > > > > > > > > > > Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. Sign up now. > _______________________________________________ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > > > > > > def fibn(n): > > a,b=15,2 > > while a>n: > > print a, # it is same like print a, a, b = a, a+b > You can not print this. SyntaxError: invalid syntax > > a,b=a,a+b > > fibn(-1) > > > > > -- > > Grigor Kolev <grigor.ko...@gmail.com> > > > > _________________________________________________________________ > Hotmail: Powerful Free email with security by Microsoft. > http://clk.atdmt.com/GBL/go/196390710/direct/01/ > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > <http://mail.python.org/pipermail/tutor/attachments/20100130/6d53b605/attachment-0001.htm> > > ------------------------------ > > Message: 2 > Date: Sun, 31 Jan 2010 01:40:41 +0200 > From: Grigor Kolev <grigor.ko...@gmail.com> > To: invincible patriot <invincible_patr...@hotmail.com> > Cc: tutor@python.org > Subject: Re: [Tutor] can any one help > Message-ID: <1264894841.6587.39.ca...@dedal-laptop> > Content-Type: text/plain > > Excuse me but I have question too. > Why when i write this function in python shell not work says > SyntaxError: invalid syntax > but when I use IDLE make endless loop > Sorry I also teach Python. >> def fibn(n): >> a,b=15,2 >> while a>n: >> print a, # it is same like print a, a, b = a, a+b >> You can not print this. SyntaxError: invalid syntax >> a,b=a,a+b >> fibn(-1) > -- > Grigor Kolev <grigor.ko...@gmail.com> > > > > ------------------------------ > > Message: 3 > Date: Sat, 30 Jan 2010 23:46:30 +0000 > From: invincible patriot <invincible_patr...@hotmail.com> > To: <tutor@python.org> > Subject: [Tutor] please help me > Message-ID: <col107-w365777c651fe3fff81459ce2...@phx.gbl> > Content-Type: text/plain; charset="windows-1252" > > > hii am stuck in these questions can someone please help me in solving and > writing programme for these tasks > please help me > > > > > 1 1.1 Write a Python program with a loop that prints out a sequence of > numbers as follows:151311...31-1 > > 1.2 Write a small Python program that generates the list of all pairs of > characters c andits doubling 2 c, where c moves through all the letters of > the string "foobar" and prints it out.The result will look like:[(?f?, ?ff?), > (?o?, ?oo?), (?o?, ?oo?), (?b?, ?bb?), (?a?, ?aa?), (?r?, ?rr?)]Hint: use > list comprehensions. > 1.3 Write a small Python program that > 1. prints out the length of the > string?taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu? > 2. prints out how many different characters this string contains > 3. replaces all the non-?t? characters in above string with dots ?.?. So, if > the word were?tattoo?, it would print ?t.tt..?.Hints: > (a) use a function to t-ify the string > (b) there are various ways to construct the string, either using the join > method or by runninga loop accumulating substrings. > (c) check also out what happens if you apply the conversion list(s) to a > string s. > 2 2.1 Write a function count char(s, c) that takes a string s, and a > character c and returnshow often the character c appears in the string.For > example count_char("tattoo", "t") should return 3. > > 2.2 Write a Python function char_freqency(s)that returns a dictionary which, > for eachcharacter of s as a key, stores as value how often this character > appears.For example, char_frequency("tattoo") could return {?a?: 1, ?t?: 3, > ?o?: 2} (the order ofkey:value pairs does not matter here). > Hint: Consider using the function count_char defined in 2.1. > 2.3 Write a program that translates a given string (of arbitrary length) of > DNA bases intothe RNA strand that it will produce. For this, research which > DNA bases correspond to RNA basesand create a translation table (not an > if...else clause!) in the Python program. [4 marks] > > > 3 > 3.1 consider the following list of base > sequences:ACGTACCTTACTTACCATATCGTACCTCTTACTCATThe task consists of writing a > Python program that performs a simple alignment algorithm onthese two strings > and prints out this alignment in a suitable readable form. Give a brief > commentexplaining the output format.Hints:1. Matching means the following: > for a given sequence to be matched, your program should denotewhich bases > correspond to bases in the reference sequence and which do not; in addition, > markgaps where the reference sequence contains bases which are not present in > the sample sequence.For a given sample sequence, your matching algorithm will > attempt to match as many basesas possible to those of the reference > sequence.2. This is a difficult assignment. Do not attempt it before you have > solved the others.3. For this purpose, you are allowed to research and > implement publicly documented versions ofthe Needleman-Wunsch algorithm or > similar algorithms (however, make sure that you r > efer-ence them properly!). Also make sure that your program prints out the > matches/mismatchesbetween the sequences. You should demonstrate at least two > different alignments by usingdifferent gap penalties.Instead of following > this hint, you can develop an alternative solution to the matching > problem,e.g. based on the Levenshtein distance. > > > please help me > _________________________________________________________________ > Hotmail: Trusted email with Microsoft?s powerful SPAM protection. > http://clk.atdmt.com/GBL/go/196390706/direct/01/ > -------------- next part -------------- > An HTML attachment was scrubbed... > URL: > <http://mail.python.org/pipermail/tutor/attachments/20100130/61b42551/attachment.htm> > > ------------------------------ > > _______________________________________________ > Tutor maillist - tu...@python.org > http://mail.python.org/mailman/listinfo/tutor > > > End of Tutor Digest, Vol 71, Issue 78 > ************************************* > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor