145k views
3 votes
Write code that takes in two words from user input and stores them in the variables a and b respectively. Then, the program should swap the values in a and b, and print a and b.

Note: The variable names a and b are required for this question.

Sample Run
Enter a word: apple
Enter a word: zebra
a: zebra
b: apple

1 Answer

2 votes

Answer:

Here's the Python code that takes in two words from user input, swaps their values, and prints them:

a = input("Enter a word: ")

b = input("Enter a word: ")

# Swap the values in a and b

a, b = b, a

print("a:", a)

print("b:", b)

------------------------

Sample output:

Enter a word: apple

Enter a word: zebra

a: zebra

b: apple

Step-by-step explanation:

User Matthias Hryniszak
by
8.1k points

No related questions found