Question

python rephactor 1. Write code that prints the square root of the value in the variable...

python rephactor

1. Write code that prints the square root of the value in the variable num rounded to 4 decimal places. Assume that num already has a value and that the math module has been imported.

2.

Write a function called ordinal_sum that accepts a string argument and returns the sum of the ordinal values of each character in the string. The ordinal value of a character is its numeric Unicode code point in decimal.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
# Question 1
print(round(math.sqrt(num),4))
########################################3

# Question 2
def ordinal_sum(string):
    total = 0
    for x in string:
        total += ord(x)
    return total
Add a comment
Know the answer?
Add Answer to:
python rephactor 1. Write code that prints the square root of the value in the variable...
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
  • Write code that prints the square root of the value in the variable num rounded to...

    Write code that prints the square root of the value in the variable num rounded to 4 decimal places. Assume that num already has a value and that the math module has been imported. python

  • 1. Write a function called ordinal_sum that accepts a string argument and returns the sum of...

    1. Write a function called ordinal_sum that accepts a string argument and returns the sum of the ordinal values of each character in the string. The ordinal value of a character is its numeric Unicode code point in decimal. 2. Write code that creates a Python set containing each unique character in a string named my_string. For example, if the string is 'hello', the set would be {'h', 'e', 'l', 'o'} (in any order). Assign the set to a variable...

  • USE Python 1. Assign value 555 to the variable x, write code to square the variable...

    USE Python 1. Assign value 555 to the variable x, write code to square the variable x and print out the result. 2. Given a string x, write a program to check if its first character is the same as its last character. If yes, the code should output "True" . 3. We defined two variables, x = 'Python' and y = '3.0'. Write code to concatenate the two numbers (the result should be 'Python3.0').

  • Convert the code you developed to obtain square root value into a function that returns square...

    Convert the code you developed to obtain square root value into a function that returns square root of a float value argument. The answer is of float type. This function can be named sqrtC and it has one (float) parameter going in and one value (the result) coming out. Write code in C language.

  • Write a python code that takes in an number 0-9 and prints out the word of...

    Write a python code that takes in an number 0-9 and prints out the word of the number. For example 1 would print out one. Below is the skeleton of the code that needs to be filled in. def num2string(num): """ Takes as input a number, num, and returns the corresponding name as a string. Examples: num2string(0) returns "zero", num2string(1)returns "one" Assumes that input is an integer ranging from 0 to 9 """ numString = "" ################################### ### FILL IN...

  • PYTHON 1- Write a function that receives a string value as a parameter, converts its first...

    PYTHON 1- Write a function that receives a string value as a parameter, converts its first character to uppercase and returns the first character. 2- Test your function by writing a main, which calls your function and prints its return value. 3- Save your program in a file called firstChar.py and use the following link to submit your file.  

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • Your code must approximate the square root of an integer between 0 and 2^31-1 Using integer...

    Your code must approximate the square root of an integer between 0 and 2^31-1 Using integer maths is sufficient (no floating point or fractions are required); your code will return the truncated (integer portion) of the square root. Your code must be in an assembly language subroutine which is called by a C function for testing. Be sure to use registers according to the ARM calling convention. Base your software on the following pseudocode: Approximate square root with bisection method...

  • Use Python WingPersonal to compile and also please give output Math and String operations Write a...

    Use Python WingPersonal to compile and also please give output Math and String operations Write a script to perform various basic math and string operations. Use some functions from Python's math module. Generate formatted output. Basic math and string operations Calculate and print the final value of each variable. a equals 3 to the power of 2.5 b equals 2 b equals b + 3 (use +=) c equals 12 c = c divided by 4 (use /=) d equals...

  • Python The Python "<" and ">" comparison operators can be used to compare which string variable...

    Python The Python "<" and ">" comparison operators can be used to compare which string variable has a greater value based on comparing the ASCII codes of the characters in each string, one by one. To take some examples: "tets" > "test" returns True because the third letter of the first string, "t", has a greater value than the third letter of the second string, "s". "testa" > "test" returns True because—while the first four letters in both words are...

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