PYTHON:
def printHelloWorldFunction():
print("Hello, world!")
return
Could you please explain the use of putting the 'return' command at the end of the function block? Is it redundant?
printHelloWorldFunction() with return statement at the end of function block
// Screenshot of the code

// Sample output

// code to copy
def printHelloWorldFunction():
print("Hello, world!")
return
printHelloWorldFunction() with out return statement at the end of function block
// Screenshot of the code

// Sample output

// code to copy
def printHelloWorldFunction():
print("Hello, world!")
Explanation:
purpose-1 :
from the above screenshots we can observe that with and with out return statement at the end of printHelloWorldFunction() function block prints the same output.
However the use of return statement inside python function block is mainly for "outputting some value from this function to caller ".
A python function accepting parameters and returning a value.uses return is for the caller.
return should be used for recursive functions/methods or you want to use the returned value for later applications .
simple terms if python the return statement is used when a function is ready to return a value to its caller otherwise return can be ignored.
purpose-2:
The return statement allows you to terminate the execution of a function before you reach the end.The flow of execution immediately returns to the caller.
// Screenshot of the code 
// Sample output

// code to copy
def ret(n):
if n > 9:
print("two digits")
return "two digits"
else :
print("one digit")
return "one digit"
return
PYTHON: def printHelloWorldFunction(): print("Hello, world!") return Could you please explain the use of putting the 'return'...
In python using a def main() function, Write a function that will print a hello message, then ask a user to enter a number of inches (should be an integer), and then convert the value from inches to feet. This program should not accept a negative number of inches as an input. The result should be rounded to 2 decimal places(using the round function) and printed out on the screen in a format similar to the example run. Use a...
Please can I have a UML Class diagram for the Python program below: def main(): print() print("Welcome to Caesar Encryption and Viginere Decryption Cipher") print() print("Please select an option") option = "c" while option == "c": hello = input('Choose Caesar Cipher encrypt 1:\n' 'Choose Viginere Cipher Decrypt 2:\n') message = input('Enter a message: ') password = input('Enter a password: ') if hello == '1': viginere_cipher(message, password) elif hello == '2': viginere_cipher_decrypt(message, password) print() print("Choose an option") option = input('Enter c...
Explain please
II. (7 points) Consider the following bit of pseudocode: for (int k = 1; ks Ign; k++) (for (int i = 1; i r: i++) Print "Hello World"; for (int j-1;jsn:j++) Print "Hello World" when n = 2, how many times will "Hello World" be printed? When n 4, how many times will "Hello World be printed? O Assuming that the print is the basic operation, what is the complexity function of this pseudocode?
II. (7 points) Consider...
import random fave_word = 'hello' # add 'world' and a random number (between 0-3) of 'Bob's to this word fave_word += "world" rand_num = random.randint(0,3) if rand_num == 0: fave_word += '' elif rand_num == 1: fave_word += 'Bob' elif rand_num == 2: fave_word += 'BobBob' elif rand_num == 3: fave_word += 'BobBobBob' else: fave_word += '' print(fave_word) Looking for a way to turn this into a function and cut down on redundant code. (python)
def plusThetaeigenket(theta):
return np.array([np.cos(theta/2),np.sin(theta/2)])
print("|+theta> = ",plusThetaeigenket,"\n")
def minusThetaeigenket(theta):
return np.array([-np.sin(theta/2),np.cos(theta/2)])
print("|-theta> = ",minusThetaeigenket,"\n")
Can you please help to solve where this python code went wrong
for display the correct eigen ket value for theta? Thank you
|<+y|-y>l^2 = 0.9999999999999996 ||<+y|-x>l^2 = 0.4999999999999998 -4 print("*Exercise 30.5\n"), -5 #function defination for plus and minus theta eigenkets -6 def plusThetaeigenket(theta): +7 return np.array([np.cos(theta/2), np.sin(theta/2)]), -8 print("[+theta> = ",plusThetaeigenket,"\n"), *Exercise 30.5 -9 +theta> = <function plus Thetaeigenket at Ox00000160BCO9CD08> o def minus Thetaeigenket(theta):...
Python Please, If possible, please continue with/ use code
already given
File Commands: u/a
Write a function named, file_commands, that
takes the name of a file as a parameter.
The function processes the contents the file as follows:
For file lines that begin with the letter 'a',
calculate & print the integer average of the numbers on the
line.
For file lines that begin with the letter 'u', print
the upper case format for each word following the u.
Sample...
PYTHON please help! im stuck on this homework
question, THANK YOU! please follow the rules!
Give a recursive python implementation of the following function: def check_Decreasing_Order(lissy): Given lissy, a python list of integers, the above function will return True if lissy is sorted in decreasing order, otherwise it will return false. For example, print(check_Decreasing Order([100,50,8, -2])) True print(check_Decreasing_Order([108,50,8,2,35])) False Implementation Requirements: 1. Your implementation must be recursive. 2. If you need more parameters, you may define new functions or helper...
Hello, This is what i wrote: def squareEach(nums): answer = [] for num in nums: answer.append(num*num) return answer def sumList(nums): answer = 0 for num in nums: answer += num return answer def toNumbers(nums): new_nums = [] for i in nums: new_nums.append(int(i)) return new_nums def main(): fileName = input("What file are the numbers in? ") sum = 0 with open(fileName, 'r') as infile: for line in infile: nums.append(line) print(nums) nums = toNumbers(line) print(nums) squares = squareEach(nums) print(nums) sum += sumList(squares)...
PYTHON: Im stuck here, big O notation and runtime. What
is it and Why are they those? Please look at the pic, need help as
Im confused. Thank You!
def method3(n): for i in range(n): for j in range(100): for k in range(n): print(i+j+k) What is the runtime (tightest/closest bound in terms of O) for the above python function (method 3)? Please briefly explain. Enter your answer here def method4(n): for i in range(n): for j in range(n, o, -2):...
In Python, please change this function so if someone inputs an invalid age (string, float, number below 0), print "wrong". Use the "isdigit()" function -------------------------- def age_name(): name = input("Enter name:") age = int(input("Enter age:")) print("Hello", name) if(age <= 18): print("Child") elif(age <= 64): print("Adult") else: print("Senior")