Dec-03-2017, 11:22 AM
Hello guys.while i was learning python in class i couldnt understand the string conversations at all.And now we have homework which is hard for me to do.
[Image: 2zfk27c.png]
i couldnt copy them i snipped instead.
Thank you
Homework about string conversions
|
Dec-03-2017, 11:22 AM
Hello guys.while i was learning python in class i couldnt understand the string conversations at all.And now we have homework which is hard for me to do. [Image: 2zfk27c.png] i couldnt copy them i snipped instead. Thank you
Dec-03-2017, 11:54 AM
show your attempted code, and where you are having a problem
Dec-03-2017, 12:13 PM
actually there is no attempt.I dont know how to start to do it.i need the whole solution
Dec-03-2017, 12:15 PM
Dec-03-2017, 12:17 PM
Dec-03-2017, 12:19 PM
Did you read your assignment?
There is very, very useful hint... It outlines the neccessary steps
Dec-03-2017, 12:29 PM
(This post was last modified: Dec-03-2017, 12:29 PM by stiletto009.)
okay so im typing down what i know for now.
def get_acronym(s): a="" for i in s: if letter.isupper() True:our lecturer didnt explain commands and stuff.we just copy pasted in class so now im stuck here.
Dec-03-2017, 01:23 PM
As it says, first split the string into an array with the .split() function, then check if the first letter of each element is an uppercase letter, if it is, add the letter to a blank string (''), then print it out.
Dec-03-2017, 05:16 PM
any helps?
Dec-06-2017, 10:40 AM
(This post was last modified: Dec-06-2017, 10:59 AM by gruntfutuk.)
Try entering the following into the interactive shell for python 3:
'What the f*** went wrong?'.split() ['Read', 'The', 'F******', 'Manual'][0][0].isupper() (Dec-03-2017, 12:29 PM)stiletto009 Wrote: okay so im typing down what i know for now.Ok, let's explain what you have. def is the start of a definition of a block of code (indented by 4 spaces under the row starting def) that constitutes a function. Much like sin in mathematics is a function that when used in the form sin(x) will return the sin value of x in place of wherever it was referenced.A function in programming can be used to return not just simple mathematical values, but strings of characters and even complex data structures. So, for the square of a number, you could write the function: (This is a very clumsy example.) def mysquare(x): y = x * x return y mynum = 10 squareofmynum = mysquare(mynum) print(squareofmynum)A function needs to return a value when it finishes executing. It can have a return statement anywhere, and execution of a function ends when it encounters a return statement. Programme flow continues from where it was called. A function is not much use unless it is called. In the example, I could have called it from the print statement: print("Square of 64 is:", mysquare(64)) In an if statement, you evaluate an expression (a calculation, comparison of strings, some other test) to see if the result is either True or False. If the result is True, all the statements under the if line and indented 4 spaces are executed.Here's an example: num = -23 if num > 0 : print('Hello. I have a positive number.') if num % 2 == 0: print("It is an even number.") else: print("It is an odd number") else: if num == 0: print('I have nothing to say.') else: print('I am feeling negative.')So, you know how to write a function. You know how to use an if statement. You've already shown some understanding of lists and using loops. Some clues have been given on how to do what you need to do. I think you probably have what you need to make a very good attempt.
I am trying to help you, really, even if it doesn't always seem that way
|
|