Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 3 8 the output is: 8 3 Your program must define and call the following function. swap_values() returns the two values in swapped order. def swap_values(user_val1, user_val2)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a program whose input is two integers and whose output is the two integers swapped.

Ex: If the input is:

3 8

the output is:

8 3

Your program must define and call the following function. swap_values() returns the two values in swapped order.
def swap_values(user_val1, user_val2)

vall
17 print (user_val2)
Develop mode Submit mode
Submit for grading
Coding trail of your work What is this?
Invalid date null0,0,0 M------ min:16
Latest submission - Invalid date on Invalid date
Only show failing tests
1:Compare output ▲
Traceback (most recent call last):
File "main.py", line 14, in <module>
user_vall,user_val2=swap_values
TypeError: cannot unpack non-iterable function object
Output differs. See highlights below. Special character legend
Input
When done developing your program, press the Submit for grading button below. This will
submit your program for auto-grading.
Your output
Expected output
5
Enter First Number: Enter Second Number:
5 44
Total score: 0/10
Download this submission
0/2
Transcribed Image Text:vall 17 print (user_val2) Develop mode Submit mode Submit for grading Coding trail of your work What is this? Invalid date null0,0,0 M------ min:16 Latest submission - Invalid date on Invalid date Only show failing tests 1:Compare output ▲ Traceback (most recent call last): File "main.py", line 14, in <module> user_vall,user_val2=swap_values TypeError: cannot unpack non-iterable function object Output differs. See highlights below. Special character legend Input When done developing your program, press the Submit for grading button below. This will submit your program for auto-grading. Your output Expected output 5 Enter First Number: Enter Second Number: 5 44 Total score: 0/10 Download this submission 0/2
5.18 LAB: Swapping variables
Write a program whose input is two integers and whose output is the two integers swapped.
Ex: If the input is:
3
8
the output is:
83
Your program must define and call the following function. swap_values() returns the two values in swapped order.
def swap_values (user_val1, user_val2)
440292.2711150.qx3zqy7
LAB
ACTIVITY
5.18.1: LAB: Swapping variables
1 # Define Function
2 def swap_values(user_val1,user_val2):
3
temp=user_val1
4 # Swap number using temporary variable
56
user_val1=user_val2
6
user_val2=temp
7 # Return values after swap
8
return user_val1,user_val2
9 # User input first number
10 num1 = input('Enter First Number: ')
11 # User input second number
12 num2 =
13 # Function
input('Enter Second Number: ')
14
user_val1.user_val2-swap_values
main.py
0/10
Load default template...
Transcribed Image Text:5.18 LAB: Swapping variables Write a program whose input is two integers and whose output is the two integers swapped. Ex: If the input is: 3 8 the output is: 83 Your program must define and call the following function. swap_values() returns the two values in swapped order. def swap_values (user_val1, user_val2) 440292.2711150.qx3zqy7 LAB ACTIVITY 5.18.1: LAB: Swapping variables 1 # Define Function 2 def swap_values(user_val1,user_val2): 3 temp=user_val1 4 # Swap number using temporary variable 56 user_val1=user_val2 6 user_val2=temp 7 # Return values after swap 8 return user_val1,user_val2 9 # User input first number 10 num1 = input('Enter First Number: ') 11 # User input second number 12 num2 = 13 # Function input('Enter Second Number: ') 14 user_val1.user_val2-swap_values main.py 0/10 Load default template...
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Still unsuccessful

# Define function
def swap_values(user_val1,user_val2):
# Perform swap
    temp = user_val1
    user_val1 = user_val2
    user_val2 = temp
# Returned numbers
    return user_val1,user_val2
# User input first number
num1 = input("Enter first number: ")
# User input second number
num2 = input("Enter Second Number: ")
# Call the function
user_val1,user_val2 = swap_values(num1,num2)
# Print the returned number
print(user_val1,user_val2)

11/21 M0--0-0-0---- nul10 min:23
Latest submission - Invalid date on Invalid date
Only show failing tests
1:Compare output
Output differs. See highlights below. Special character legend
Your output
Expected output
2:Unit test ^
Input 5
swap_values(-1, 10)
3:Unit test ^
4:Unit test
swap_values(9, 0)
Enter first number: Enter Second Number: 5 4
Your output Enter first number:
5 4
Your output Enter first number:
Total score: 0 / 10
Download this submission
0/2
0/2
0/3
0/3
Transcribed Image Text:11/21 M0--0-0-0---- nul10 min:23 Latest submission - Invalid date on Invalid date Only show failing tests 1:Compare output Output differs. See highlights below. Special character legend Your output Expected output 2:Unit test ^ Input 5 swap_values(-1, 10) 3:Unit test ^ 4:Unit test swap_values(9, 0) Enter first number: Enter Second Number: 5 4 Your output Enter first number: 5 4 Your output Enter first number: Total score: 0 / 10 Download this submission 0/2 0/2 0/3 0/3
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education