Question

Question 1 5 pts data = 63.7 67.7 67.9 76 -901 80.3 84.8 93.9 84.8 76 80.3 85.8 89.3 93.9 98.5 95.9 183 -901 98.5 97.3 96.2 9Question 4 5 pts The ordinary math.sqrt e function in Python does not support imaginary numbers (square root of negatives). T

Please use python and show the code used.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Here's how you can solve these two problems. I have put comments so that its easier for you to understand
Let me know if you have any question. Keep learning and stay safe :)
PS: If you are satisfied with my answer, please consider voting it up. It really helps.

Question 1:

# Input data string
data = """63.7 67.7 67.9 76 -901 80.3
        -901 -901 81.3"""

# Split data by a " ", convert each item to float and store in a list called arr
arr = [float(x) for x in data.split()]

sum = 0
count = 0
for item in arr:
    # If item is not 901, consider for average
    if item != -901:
        sum += item
        count += 1

# Printing average
print("Average:", sum/count)


Question 4:

import math
import cmath

def sqrt(num):
    # If the number is positive, use math.sqrt
    if num >= 0:
        return math.sqrt(num)
    # If the number is negative, use cmath.sqrt
    elif num < 0:
        return cmath.sqrt(num)

# Driver code to test the above function
positive_num = 9
negative_num = -9
print("Square root of {}: {}".format(positive_num, sqrt(positive_num)))
print("Square root of {}: {}".format(negative_num, sqrt(negative_num)))

Output:

Lili Result Execute > Share main.py STDIN 1 # Input data string 2 data 63.7 67.7 67.9 76 -901 80.3 3 -901 -901 81.3 $py

Llı Result $python3 main.py Square root of 9: 3.0 Square root of -9: 3j Execute | Share main.py STDIN 1 import math 2 import

Add a comment
Know the answer?
Add Answer to:
Please use python and show the code used. Question 1 5 pts data = 63.7 67.7...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Steps Open the Heart Rate Dataset in Excel Using the classification of variables from Unit 1 assignment as qualitativ...

    Steps Open the Heart Rate Dataset in Excel Using the classification of variables from Unit 1 assignment as qualitative, quantitative discrete, or quantitative continuous, match each of the 3 variables to the most appropriate graph type. (For example, qualitative data can best be displayed with a pie chart or bar graph; continuous numerical data can best be displayed using a histogram) Use the graphing functions in Excel to create an appropriate graph of the data for each variable. Remember to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT