Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Function that will take the input data and place it in a sentence

I want to create a a string formatting function that prints first name, last name and age into a sentence.

This is my code:

def my_string_formatting(firstname, lastname, age):
    print("Hello, my name is "+ firstname + lastname + "I'm " + str(age))

and this is my input and output target:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

| Input                 | "john" && "doe" && 37               |
+-----------------------+-------------------------------------+
| Expected Output       | Hello, my name is john doe, I'm 37.

>Solution :

You can can do this easily using an fstring:

def my_string_formatting(firstname, lastname, age):
    print(f"Hello, my name is {firstname} {lastname}, I'm {age}.")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading