PYTHON
Create a function called squareValue. squareValue will calll the function getValue() to square the value and return it back to the main portion of the program. In main call squareValue which will call getValue.
def getValue():
val = int(input("Enter a number"))
return val
myValue = getValue()
print("The value entered is ", myValue)
Process:
call the getValue() function and store the data returned by the getValue() into variable called 'val'. Then return the square of variable 'val'.
Algorithm:
squareValue():
1. val=getValue()
2. return val*val
Code:
#getValue() - already given
def getValue():
val = int(input("Enter a number: "))
return val
#squareValue()
def squareValue():
'''
Process:
call the getValue() function and store the data returned by
the getValue() into variable called 'val'.
Then return the square of variable 'val'
'''
val=getValue()
return val*val
#main portion
myValue=squareValue() #calling squareValue()
print("Square: ",myValue)
Output:
Enter a number: 5
Square: 25
Please refer to the screenshots below for correct indentations
PYTHON Create a function called squareValue. squareValue will calll the function getValue() to square the value...
Hello everyone! I am working on my assignment for C++ and I'm having a bit of trouble on the value producing functions, I am creating a program wherein I have to input a value and I need to create a function called square value where in it will square the value I have input. I cannot seem to figure out this part. Here is the code that I have so far, and thank you for any help. I greatly appreciate...
Python: Create a function count_target_in_list that takes a list of integers and the target value then counts and returns the number of times the target value appears in the list. Write program in that uses get_int_list_from_user method to get a list of 10 numbers, then calls the count_target_list method to get the count then prints the number of times the target was found in the list. def get_int_list_from_user(): lst=[] y = int(input("Enter number of numbers")) for x in range(y): lst.append(int(input("Enter...
1. Create a Python script file called Assignment_Ch06-02_yourLastName.py. (Replace yourLastName with your last name.) 2. Write a Python program that prompts the user for a sentence, then replaces all the vowels in the sentence with an asterisk: '*' Your program should use/call your isVowel function from Assignment_Ch06-01. You can put the isVowel() function in a separate .py file, without the rest of the Ch06-01 code, and then import it. 6-01 CODE: def isVowel(x): if x in "aeiouyAEIOUY": return True else:...
import mathdef limitReached(val,last): return abs(val - last) < 1e-2def improvateEstimate(val,n): return (val + n / val) * 0.5def squareroot(n): val = n while True: last = val val = improvateEstimate(val,n) if limitReached(val,last): break return valwhile True: n=(input(' Enter a positive number or enter/return to quit: ')) if n=='': break else: print('The program\'s estimate is :',squareroot(eval(n))) print('Python\'s estimate is :', math.sqrt(eval(n))) print()
Implement a Python function that prints integers from a to b. The main part of the program should ask the user to input a and b and call the function. # Display integers a, a+1, a+2, ..., b def display(a,b): ## complete your work here ## return a = int(input("Please prvide a value for a: ")) b = int(input("Please prvide a value for b: ")) display(a,b)
For Python debugExercise12.py is a recursive function that accepts an integer argument, n, and prints the numbers 1 up through n. By debugging these programs, you can gain expertise in program logic in general and the Python programming language in particular. def main(): # Local variable number = 0 # Get number as input from the user. number = int(input('How many numbers to display? ')) # Display the numbers. print_num(number) # The print_num function is a a recursive function #...
I'm trying to run the code in Python below and keep getting invalid syntax. What's wrong? Thanks for any help! def even(n): if n%2==0 #Enter a Number def main(): n=int(input("Enter a number: ")) #If even print "Number is even" if(even(n)): print("The number is even") #If odd print "Number is odd" else: print("The number is odd") main() #Call the main function
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...
Python help! Any help is appreciated, thank you! Fill in the missing function, monthString(), in the program. The function should take number between 1 and 12 as a parameter and returns the corresponding month as a string. For example, if the parameter is 1, your function should return "January". If the parameter is 2, your function should return out "February", etc. def monthString(monthNum): """ Takes as input a number, monthNum, and returns the corresponding month name as a string. Example:...
THIS CODE IS IN PYTHON #This program calls a function from the main function def getInput(): ''' This function gets the rate and the hours to calculate the pay ''' userIn = float(input("Enter the rate: ")) print(userIn) inputHours = float(input("Enter the hours: ")) print(inputHours) def main(): getInput() main() YOU NEED TWO FUNCTIONS : main() function get_inputs function