37.1k views
3 votes
PYTHON QUESTION

Exercise 9.3.9: Full Name & Citation
points
Write a program that asks a user for their first and last name and save them
to two variables.
Then print out their full name (First_name Last_name) and then a citation
(Last name, First name)
For example, if the user input the following:
First name: Roger
Last Name: Brown
Your program output should be the following:
Full name : Roger Brown
Citation: Brown, Roger
Use swapping to switch the order of your variables!

2 Answers

4 votes

Final answer:

A Python program can ask for a user's first and last names, display them, and then print the citation by swapping the name order. The 'input' function is used to collect names, and the swap is done by reassigning variables.

Step-by-step explanation:

To write a Python program that asks a user for their first name and last name, you can use the input() function. After that, you will print the full name and citation, with the order of the names swapped using variable swapping.

Example Python Program

first_name = input("Enter your first name: ")
last_name = input("Enter your last name: ")
# Display full name
print("Full name :", first_name, last_name)
# Swap the variables to get the citation format
first_name, last_name = last_name, first_name
# Display citation
print("Citation:", first_name, ",", last_name)

When running this program, after the user provides their first and last names, it will show the full name as 'First_name Last_name' and the citation as 'Last_name, First_name'.

User Soroush Mirzaei
by
5.6k points
6 votes

Final answer:

To handle the exercise, gather the user's first and last name, print the full name, perform variable swapping, and print the citation in the format 'Last name, First name'.

Step-by-step explanation:

To complete this exercise in Python, we will prompt the user to enter their first name and last name, save these values to variables, and then utilize variable swapping to generate the desired output with full name and citation format. Here is a step-by-step solution:

  1. Ask the user for their first name and save it to a variable called first_name.
  2. Ask the user for their last name and save it to a variable called last_name.
  3. Print the full name by concatenating first_name and last_name with a space between them.
  4. Use variable swapping to switch the values of first_name and last_name.
  5. Print the citation format by concatenating last_name, a comma, a space, and then first_name.

Here is an example of the code:

first_name = input('Enter your first name: ')
last_name = input('Enter your last name: ')
print('Full name:', first_name, last_name)
first_name, last_name = last_name, first_name # This is the swapping
print('Citation:', first_name + ',', last_name)
User Kame
by
7.0k points