Python: Display your details like name, age, address in three different lines
Python Basic: Exercise-37 with Solution
Write a Python program that displays your name, age, and address on three different lines.
Pictorial Presentation:
Sample Solution:-
Python Code:
# Define a function 'personal_details'.
def personal_details():
# Define variables 'name' and 'age' and assign values to them.
name, age = "Simon", 19
# Define a variable 'address' and assign a value to it.
address = "Bangalore, Karnataka, India"
# Print the personal details using string formatting.
print("Name: {}\nAge: {}\nAddress: {}".format(name, age, address))
# Call the 'personal_details' function to display the details.
personal_details()
Sample Output:
Name: Simon Age: 19 Address: Bangalore, Karnataka, India
Explanation:
The said code defines a function called "personal_details" which does not take any arguments. Within the function, three variables are defined: "name" is assigned the string "Simon", "age" is assigned the integer 19, and "address" is assigned the string "Bangalore, Karnataka, India".
The function then uses the print() function to output the values of these three variables in a formatted string. The curly braces {} are placeholders for the values that will be passed through the .format() method.
Finally the function is called at the end of the code and prints the values of name, age and address.
Flowchart:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to add two objects if both objects are an integer type.
Next: Write a Python program to solve (x + y) * (x + y).
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://198.211.115.131/python-exercises/python-basic-exercise-37.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics