|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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!! ![]() |
|
#2
|
|||||||||
|
|||||||||
|
Quote:
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:
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:
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:
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:
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:
Files are easy in python. open one with: Code:
file = open("filename", 'r')
readlines() will read in all the lines of a file and construct a list containing all the read in lines. Quote:
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! |
|
#3
|
|||
|
|||
|
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
|
|
#4
|
|||
|
|||
|
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.
|
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Help me with this tasks!!..Be my saviour |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|