Swapping Values in python
Summary
In this lab, you complete a Python program that swaps values stored in three variables and determines maximum and minimum values. The Python file provided for this lab contains the necessary input and output statements.
You want to end up with the smallest value stored in the variable named first and the largest value stored in the variable named third. You need to write the statements that compare the values and swap them if appropriate.
Comments included in the code tell you where to write your statements.
Instructions
101 22 -23 630 1500 9 21 2 2
Grading
When you have completed your program, click the Submit button to record your score.
# Swap.py - This program determines the minimum and maximum of three values input by
# the user and performs necessary swaps.
# Input: Three int values.
# Output: The numbers in numerical order.
first = 0
second = 0
third = 0
# Get user input
first = int(input("Enter first number: "))
second = int(input("Enter second number: "))
third = int(input("Enter third number: "))
# Test to see if the first number is greater than the second number
# Test to see if the second number is greater than the third number
# Test to see if the first number is greater than the second number again
# Print numbers in numerical order
print("Smallest: " + str(first))
print("Next smallest: " + str(second))
print("Largest: " + str(third))
If you have any doubts, please give me comment...
Code:
# Swap.py - This program determines the minimum and maximum of three values input by
# the user and performs necessary swaps.
# Input: Three int values.
# Output: The numbers in numerical order.
first = 0
second = 0
third = 0
# Get user input
first = int(input("Enter first number: "))
second = int(input("Enter second number: "))
third = int(input("Enter third number: "))
# Test to see if the first number is greater than the second number
if first>second:
first, second = second, first
# Test to see if the second number is greater than the third number
if second>third:
second, third = third, second
# Test to see if the first number is greater than the second number again
if first>second:
first, second = second, first
# Print numbers in numerical order
print("Smallest: " + str(first))
print("Next smallest: " + str(second))
print("Largest: " + str(third))
Swapping Values in python Summary In this lab, you complete a Python program that swaps values...
Multiple Conditional Statements Summary In this lab, you complete a Python program that calculates an employee's annual bonus. Input is an employee's first name, last name, salary, and numeric performance rating. If the rating is 1, 2, or 3, the bonus rate used is .25, .15, or .1 respectively. If the rating is 4 or higher, the rate is 0. The employee bonus is calculated by multiplying the bonus rate by the annual salary. Variables have been declared for you,...
unctions with No Parameters Summary In this lab, you complete a partially prewritten Python program that includes a function with no parameters. The program asks the user if they have preregistered for art show tickets. If the user has preregistered, the program should call a function named discount() that displays the message "You are preregistered and qualify for a 5% discount." If the user has not preregistered, the program should call a function named noDiscount() that displays the message "Sorry,...
Write a python program write a function numDigits(num) which counts the digits in int num. Answer code is given in the Answer tab (and starting code), which converts num to a str, then uses the len() function to count and return the number of digits. Note that this does NOT work correctly for num < 0. (Try it and see.) Fix this in two different ways, by creating new functions numDigits2(num) and numDigits3(num) that each return the correct number of...
Propose: In this lab, you will complete a Python program with one partner. This lab will help you with the practice modularizing a Python program. Instructions (Ask for guidance if necessary): To speed up the process, follow these steps. Download the ###_###lastnamelab4.py onto your desktop (use your class codes for ### and your last name) Launch Pyscripter and open the .py file from within Pyscripter. The code is already included in a form without any functions. Look it over carefully....
Two variables named largest and smallest are assigned for you. Use these variables to store the largest and smallest of the three integer values. You must decide what other variables you will need and initialize them if appropriate. Write the rest of the program using assignment statements, if statements, or elif statements as appropriate. There are comments in the code that tell you where you should write your statements. The output statements are written for you. Execute the program. Your...
Can someone help me with this Python code Summary In this lab, you work with the same Python program you worked with in Labs 5-1 and 5-3. As in those earlier labs, the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. However, in this lab you should accomplish this using a while loop with a break statement. Instructions Make sure that the file NewestMultiply.py is selected and open. Write...
Please write in Python language. Assignment 5 0 Write a program that reads in integers and then determines whether input value is prime number or not(using for statement) • First input Input number: 18457 yes . Second input Input number: 52 no
write the solution of the program by python 3 language : I need the program using list : You are given a non-decreasing sequence of n positive integers a1,a2,…,an. Print the number of distinct values in the sequence. For example, if the sequence is 1,2,2,2,3,4,4,5,7,10, the answer is 6 since distinct values are 1,2,3,4,5,7,10. Input The first line contains a positive integer n (1≤n≤1000) — the length of the sequence. The second line contains n space-separated positive integers a1,a2,…,an (1≤ai≤1000)...
in Python please 6.8 LAB: Adjust values in a list by normalizing When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This can be done by normalizing to values between 0 and 1, or throwing away outliers. Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, adjust each integer in...
I am writing python code. I submitted an assignment but the professor said it was a modularization. Can you help me see what part of the code is modularization? Pseudocode: 1. Decalre MainMethod () function: # A. Parameters: Three numbers # B. Put the three numbers in reverse # 2. Main Program # A. Initialize Varibles # B. Accepts three values from the user # C. Invoke MainMethod () function, passing the three numbers as arguments in reverse # D....