Python Forum
Homework about string conversions
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Homework about string conversions
#1

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
Reply
#2
show your attempted code, and where you are having a problem
Reply
#3
actually there is no attempt.I dont know how to start to do it.i need the whole solution
Reply
#4
(Dec-03-2017, 12:13 PM)stiletto009 Wrote: i need the whole solution
Unfortunately for you, this is not going to hapen...
Reply
#5
(Dec-03-2017, 12:15 PM)buran Wrote:
(Dec-03-2017, 12:13 PM)stiletto009 Wrote: i need the whole solution
Unfortunately for you, this is not going to hapen...

so.how do i suppose to do it?i didnt understand the logic of it.
Reply
#6
Did you read your assignment?
There is very, very useful hint... It outlines the neccessary steps
Reply
#7
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.
Reply
#8
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.
Reply
#9
any helps?
Reply
#10
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.

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.
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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020