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, 12:13 PM)stiletto009 Wrote: [ -> ]i need the whole solutionUnfortunately for you, this is not going to hapen...
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.
'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 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.
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.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.
print("Square of 64 is:", mysquare(64))
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.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.