Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old April 17th, 2008, 04:52 AM
ayeyo ayeyo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 6 ayeyo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 38 m 17 sec
Reputation Power: 0
Help me with this tasks!!..Be my saviour

Hi,

I have these tasks for my lab work to complete...am a beginner to python programming so these tasks are making me no matter how hard i try..pls help me!!

1. Write a program that prints an n-level stair case made of text. The user should choose the text character and the number of stairs in the stair case
*
**
***
****

2.Write a function that given the string “original” create a new string “dramatic’ that has two consecutive copies of each letter from the original string. For example the string “argh” would appear “aarrgghh”


3.Write a function, sliding(word, num)that behaves as follows. It should print out each slice of the original word having length num, aligned vertically as shown below. A call to sliding(examples, 4) would produce:
exam
xamp
ampl
ples


4.Write a program that uses loops to generate an n x n times table. The program should get n from the user. As a model here is a 4 x4 version:
| 1 2 3 4
----+--------------------
1 | 1 2 3 4
2 | 2 4 6 8
3 | 3 6 9 12
4 | 4 8 12 16


5.Write a function with a signature cheerlead(word) that prints a typical cheer as follows. The word robot:
Gimme an R
Gimme an O
Gimme a B
Gimme an O
Gimme a T
What did you give me?
ROBOT!!!

6.Write a program that reads a file named famous.txt and prints out the line with the longest length. In the case of a tie, you may print out only one of them. For example in the file:
Alan Turing
John von Neumann
Donald Knuth
Charles Babbage
Grace Hopper
your program should print out John von Neumann

CHALLENGE TASK
Write robust exception handling so the program does not crash if the file is not available.

Find and print out all occurrences of the longest line.
For example if the file held:
Alan Turing
Jonn von Neumann
Donald Knuth
Charles Babbage
Grace Hopper
Pete van de Beck
your program should print out:
John von Neumann
Pete van de Beck

A big big big thanks in advance!!

Reply With Quote
  #2  
Old April 17th, 2008, 10:39 AM
c-2501 c-2501 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Location: Scotland
Posts: 28 c-2501 User rank is Corporal (100 - 500 Reputation Level)c-2501 User rank is Corporal (100 - 500 Reputation Level)c-2501 User rank is Corporal (100 - 500 Reputation Level)c-2501 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 10 h 22 m 21 sec
Reputation Power: 0
Quote:
Originally Posted by ayeyo
Hi,

I have these tasks for my lab work to complete...am a beginner to python programming so these tasks are making me no matter how hard i try..pls help me!!


First let me give you the standard telling off for asking homework questions here the topic also leads me to believe you've left this to the last minute... again! (I'm a student too I know how it is, some advice; get out of this habit while you still can, it'll make things easier for you in the long run I promise)

That being the case I'm not going to give you full answers to your questions, but hopefully this info will help you get to the solutions on your own.

Quote:
Originally Posted by ayeyo
1. Write a program that prints an n-level stair case made of text. The user should choose the text character and the number of stairs in the stair case


You can use raw_input() to get simple command prompt inputs.
A for loop would be your best bet to create the n-level staircase, remember you cant iterate through an int so try the range() function.


Quote:
Originally Posted by ayeyo
2.Write a function that given the string “original” create a new string “dramatic’ that has two consecutive copies of each letter from the original string. For example the string “argh” would appear “aarrgghh”


Strings are iterable so a for loop again will work here, also probably the easiest way to concatenate a string in this operation is the += operator (its inefficient but I doubt that matters at this level of coding)


Quote:
Originally Posted by ayeyo
3.Write a function, sliding(word, num)that behaves as follows. It should print out each slice of the original word having length num, aligned vertically as shown below. A call to sliding(examples, 4) would produce:
exam
xamp
ampl
ples


Strings are sliced with the following operation: string[beginslice : endslice] remember that the string index is 0 based.
For loops again will suffice for this function.
String lengths can be obtained by the len(string) builtin

Quote:
Originally Posted by ayeyo
4.Write a program that uses loops to generate an n x n times table. The program should get n from the user. As a model here is a 4 x4 version:
| 1 2 3 4
----+--------------------
1 | 1 2 3 4
2 | 2 4 6 8
3 | 3 6 9 12
4 | 4 8 12 16


5.Write a function with a signature cheerlead(word) that prints a typical cheer as follows. The word robot:
Gimme an R
Gimme an O
Gimme a B
Gimme an O
Gimme a T
What did you give me?
ROBOT!!!


I cant think of anything new to give you for these two, the previous hints should be enough.
One thing though python allows character multiplication, i.e.
Code:
'-' * 20
gives:
'--------------------'


Quote:
Originally Posted by ayeyo
6.Write a program that reads a file named famous.txt and prints out the line with the longest length. In the case of a tie, you may print out only one of them. For example in the file:
Alan Turing
John von Neumann
Donald Knuth
Charles Babbage
Grace Hopper
your program should print out John von Neumann


Files are easy in python. open one with:
Code:
file = open("filename", 'r')
the r stands for read-only.
readlines() will read in all the lines of a file and construct a list containing all the read in lines.

Quote:
Originally Posted by ayeyo
CHALLENGE TASK
Write robust exception handling so the program does not crash if the file is not available.

Find and print out all occurrences of the longest line.
For example if the file held:
Alan Turing
Jonn von Neumann
Donald Knuth
Charles Babbage
Grace Hopper
Pete van de Beck
your program should print out:
John von Neumann
Pete van de Beck

A big big big thanks in advance!!


I dont plan on helping you with this last one, I'm not doing it to be mean, I just think perhaps you should try and work this one out on your own, its not that hard, honest!

Reply With Quote
  #3  
Old April 17th, 2008, 11:37 AM
ayeyo ayeyo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 6 ayeyo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 38 m 17 sec
Reputation Power: 0
Thanks

Yeah i know..its really bad to be lazy and ask for help..but my case is slightly different....I havent been taught properly by my lecturer..or even supported in a proper way...discovering programming is a self learning process i believe and also agree....but not something that is in your brain right from your birth which our lecturer expects from us..and is wrong...whats the base of teaching if it was like this?...every tom, **** and harry would had been a programmer if teaching was not required and all depended upon self learning...anyways i really thank you for providing me the hints...i have already done a few tasks on my own self somehow ...these were left.....ill try harder for these..thanks again

Reply With Quote
  #4  
Old April 17th, 2008, 11:57 AM
c-2501 c-2501 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Location: Scotland
Posts: 28 c-2501 User rank is Corporal (100 - 500 Reputation Level)c-2501 User rank is Corporal (100 - 500 Reputation Level)c-2501 User rank is Corporal (100 - 500 Reputation Level)c-2501 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 10 h 22 m 21 sec
Reputation Power: 0
No problem, if this lecturer is really as bad as you say I doubt you are the only one in the class experiencing these problems and I suggest you talk to your classmates and make a complaint to whoever is in charge of your course as a whole.

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Help me with this tasks!!..Be my saviour


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway