Question

In: Computer Science

use python Although clumsy, the if statements and if-else statements can be used to achieve the...

use python

Although clumsy, the if statements and if-else statements can be used to achieve the same effects as if-elif-else statements. Rewrite the speed3 function:

def speed3():

   kph=float(input('What is the speed in kph?'))

   mph=0.621371*kph

print('The speed is',mph,'mph.')

if mph>80:

   print('You are WAY over the speed limit. Your fine is $200!')

elif 65<mph<=80:

print('You are over the speed limit (65mph) . Slow down1').

elif 30<=mph<=65:

print('You are within the speed limit. Good job!')

else:

  print('You are too slow. Exit highway and use local roads!')

(a) use only if statement

(b) use only if-else statement

Solutions

Expert Solution

Code:

def speed3():
    kph=float(input('What is the speed in kph?'))
    mph=0.621371*kph
    print('The speed is',mph,'mph.')
    if mph>80:
        print('You are WAY over the speed limit. Your fine is $200!')
    if 65<mph<=80:
        print('You are over the speed limit (65mph) . Slow down1')
    if 30<=mph<=65:
        print('You are within the speed limit. Good job!')
    else:
        print('You are too slow. Exit highway and use local roads!')

Output:


Related Solutions

Python Programming This assignment will give you practice with interactive programs, if/else statements, collections, loops and...
Python Programming This assignment will give you practice with interactive programs, if/else statements, collections, loops and functions. Problem Description A small car yard dealing in second hand cars needs an application to keep records of cars in stock. Details of each car shall include registration(rego), model, color, price paid for the car (i.e. purchase price) and selling price. Selling price is calculated as purchased price plus mark-up of 30%. For example, Toyota Corolla bought for $20,000 will have the selling...
Python has an established coding style, but the style is a suggestion, and although you can...
Python has an established coding style, but the style is a suggestion, and although you can style your code using different style choices, you are strongly encouraged to be consistent. true or false
Objectives To reinforce the use of If-Else statements To learn how to use while loops Introduction:...
Objectives To reinforce the use of If-Else statements To learn how to use while loops Introduction: Mission to Mars Your friend has been playing a new Mars Colony simulator nonstop! They are always talking about how cool it would be if they could be a on the first real-life mission to Mars! To amuse your friend, you have decided to create a series of programs about the possible first colony on Mars. Problem: Where Can We Get the Best Deal?...
Describe how reflection can be used to achieve team improvement.
Describe how reflection can be used to achieve team improvement.
Although you may not be in a position to achieve long term financial goal at this...
Although you may not be in a position to achieve long term financial goal at this point in time, when you do have a steady income, how would go about ensuring you set money aside or pay into your investment plan to achieve your financial goal? Discuss how you plan to avoid using this money for anything but your financial goal.
Regular expressions are used in Python for describing and identifying specific patterns. In Python, we use...
Regular expressions are used in Python for describing and identifying specific patterns. In Python, we use “re” or “Regex” to denote regular expressions. Write the Python Code to return matching analytics word in the following given text. Write the Python Code to return how many times analytics word is provided in this text. Definitions are useful to the extent they serve a purpose. So, is defining analytics important? Yes and no. It’s not likely that we’ll ever arrive at a...
52. Consider the following five statements: i. Swaps may be used to achieve a lower cost...
52. Consider the following five statements: i. Swaps may be used to achieve a lower cost of funds for a company. ii. In an interest rate swap, the two parties swap the principal amount plus the ongoing associated interest obligations. iii. An intermediated swap is said to be ‘matched' when a bank enters into swaps with both firms involved in an interest rate swap iv. A ‘plain vanilla' swap is the fixed AUD to floating AUD swap. v. If an...
Python Please debug each python block. Do not change the algorithm. You can add statements or...
Python Please debug each python block. Do not change the algorithm. You can add statements or you can modify existing python statements. #2) The below code prints all numbers from 5 to 20. Modify the below while loop to print odd numbers from 5 to 21, # including 21. Correct syntax errors as well. i = 5 while(i<21): print(i) i = i+1
One of the advantages that functions provide is that they collect frequently-used sequences of Python statements...
One of the advantages that functions provide is that they collect frequently-used sequences of Python statements (for example, the code needed to perform a multiple-step operation) into a single named element; whenever we want to perform that operation, we just invoke (call) the function, and our program will execute the code that is associated with that function name. This avoids needless repetition of (potentially long) blocks of code, but it also makes our code reusable (other programs that we write...
in python You will be writing a program that can be used to sum up and...
in python You will be writing a program that can be used to sum up and report lab scores. Your program must allow a user to enter points values for the four parts of the problem solving process (0-5 points for each step), the code (0-20 points), and 3 partner ratings (0-10) points each. It should sum the points for each problem-solving step, the code, and the average of the three partner ratings and print out a string reporting the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT