Publicado por c
(1 intervención) el 24/01/2010 11:13:22
HOLA A TODO EL MUNDO, porfavor, necesito ayuda, estudiando para un examen proximo, no se por que no soy capaz de que me salgan estos ejercicios, me podeis ayudar o dar una opinion,,,,muchas gracias -------------------------------
Implement a code fragment that converts a date from one string format to another. Specifically, we
would like to take a date originally formatted as the string 11-10-2008 and to output the date in the form
October 11, 2008.
This task can be broken down in several steps:
- Getting the original input
- Breaking apart the original format
- Reassembling the desired result
Outputting the result to the user
- Suppose the list astronauts has the value [‘Yuri Gagarin’,’John Glenn’,’Neil Armstrong’]. Give a
single statement that adds ‘Alan Shepard’ between Yuri Gagarin and John Glenn.
Start from a list of strings named people and rearrange that list into reverse alphabetical order.
- Write a statement that takes a list named words and creates a new list words containing every
other word starting with the second (i.e. 2nd, 4th, 6th, etc.).
- Write a statement using the range() function to create a list with the contents [8,5,2].
- Assume that we have a list fruits initialized as [‘orange’,’banana’,’grape’,’lime’,’strawberry’]. Give
a single command that replaces the occurrence of ‘lime’ with the string ‘kiwi’.
Consider a string example defined as ‘This is a test. This is only a test.’. Give the type and value of
the following expressions:
- Write an expression that is True if stringA and stringB are equivalent to each other in a case-
- Assume that person is a string of the form ‘FirstName LastName’. Give a command or series of
commands that results in the corresponding string ‘Lastname, Firstname’.
- Write an expression that is True precisely when stringA is a capitalized version of stringB.
Write a script that asks the user for his/her height and weight and report his/her BMI back together with
his current status: should he/she lose weight, gain weight or stay the same.
Write a script that asks a date from the user and outputs how many days into the year it is. For example,
May 5 is the 125st day of the year. Do not worry about leap year.
Exercise 5 “Looping” (75 mins)
- Assume that word is a string, for example ‘kebab’. Write code to print out the following pattern
for the given word.
- Write a program that prints an n-level staircase made of text, such as the example for n = 4
- Write a code fragment that prompts the user to enter numbers and prints out the average of the
numbers. The program should keep asking the user to enter another number until he enters the
number 0, at which point the program should print out the average and stop. The output should
be a floating point number.
Write a program that allows a user to enter words, continuing until the user first enters a
duplicate. Your program should work as shown in the following script (underlined words are user
input). Use a function that checks if the most recent word is a duplicate.
Start entering words:
You already entered apple.
You listed 3 distinct words.
- Write a function with signature cheerlead(word) that prints a typical cheer as follows. For
example, a call to cheerlead(‘khleuven’) should print the following.
Gimme a K
Gimme an H
Gimme an L
Gimme an E
Gimme a U
Gimme a V
Gimme an E
Gimme an N
What’s that spell?
Notice the capital single letters and the appropriate use of a versus an.
Lookup the information about the Python dict class. Which data structure in Perl does this remind you
of? Instantiate a phonebook with as entries your 3 best male resp. female friends and their cell phone
number. Do this in two different ways: one way for your male friend and the other way for your female
friends. Next, implement the code w.r.t. the following:
- Print your 3 best male friends and their cell phone numbers alphabetically.
Print the first three letters of all your female friends.
- Implement a function isNotInMyMaleTop3 with a parameter person that returns True if your
phonebook does not contain that person.
- Implement a function to replace one of your female friends.