Question

In: Computer Science

python practice! 1. Create a function that takes a user choice and one number as parameters...

python practice!

1. Create a function that takes a user choice and one number as parameters and returns the operation result.

-Square: print the number square

-Sqrt: print the square root of the number

-Reverse: reverse the sign of the number (pos or neg) and print it

Note: Detect invalid choices and throw an error message – Number can be anything.

2. Create a function that takes a user choice and two numbers (start and end) as parameters.

For example, two numbers can be 5 and 40.

-Evens: print the even numbers between the two numbers, start and end.

-Odds: print the odd numbers between the two numbers, start and end.

Hint: You will have to use a range function with the numbers start and end.

Solutions

Expert Solution

Solution

1)

Code

def myfunction( number ):
square=number*number
squareroot=number**0.5
reverse=-number
print("Square of the number: ", square)
print("Square root of the number: ", squareroot)
print("After reversing sign: ", reverse)
return


try:
number = int(input("Please enter a number: "))
myfunction( number )
except:
print("Invlid entry")

Screenshot

Output

---

Program 2

Code

def myfunction( start,end ):

print("Odd numbers between",start,"to",end)

for num in range(start+1, end):
if num % 2 != 0:
print(num, end = " ")
print("\nEven numbers between",start,"to",end)
  
for num in range(start+1, end):
if num % 2 == 0:
print(num, end = " ")   
return

start = int(input("Please enter the starting number: "))

end = int(input("Please enter the end number: "))
myfunction( start,end )

Screenshpt

Output


Related Solutions

IN PYTHON Create a function called biochild.  The function has as parameters the number m...
IN PYTHON Create a function called biochild.  The function has as parameters the number m and the lists biomother and biofather.  The biomother and biofather lists contain 0’s and 1’s.  For example: biomother = [1,0,0,1,0,1] and biofather = [1,1,1,0,0,1]  Both lists have the same length n.  The 0's and 1's represent bits of information (remember that a bit is 0 or 1).  The function has to generate a new list (child).  The child...
. Create a Python function that asks the user for a number (integer). The function should...
. Create a Python function that asks the user for a number (integer). The function should then tell the user how many hundreds can go into the number, and how much is left over. Hint: the % operator calculates the remainder of a division. For example, 10 % 3 gives a result 1. Hint2: Deal with the positive and negative values in separate parts of an if-else structure. Get the calculation work for positive values first. For negative values, make...
In python I want to create a singular function that takes two parameters 'head; and 'skip'....
In python I want to create a singular function that takes two parameters 'head; and 'skip'. Head is a linked list. Skip is a non negative value. If skip is zero it should return the linked list unchanged. The skip amount determines the amount to skip over. I want to change the linked list accordingly and then return the linked list with the modifications, not a list. If you have a linked list 11 -> 12 -> 18 -> 20...
In python I want to create a singular function that takes two parameters 'head; and 'skip'....
In python I want to create a singular function that takes two parameters 'head; and 'skip'. Head is a linked list. Skip is a non negative value. If skip is zero it should return head unchanged. The skip amount determines the amount to skip over. I want to change the linked list accordingly. If you have a linked list 11 -> 12 -> 18 -> 20 -> 24 -> 32 -> 38 -> 44 and skip =2, then you should...
Q.1: create a python function that takes two integers from the user ( pass them from...
Q.1: create a python function that takes two integers from the user ( pass them from the main program). The function performs the addition operation and returns the result. In the program, ask the user to guess the result. Then, the program compares the user input ( guess) with the returned value, and displays a message that tells if the user guessing is correct or not. --define the function here --- # the program starts here print(“ This program tests...
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Write a Python function that takes two parameters: the first a list of strings and the...
Write a Python function that takes two parameters: the first a list of strings and the second a single string. The function should return True or False depending on whether the string is in the list or not. For example, if the list contains eggs, milk, bananas, and the second parameter is pumpkin, the function should return False. Thank you.
Python Problem 3 Write a function named enterNewPassword. This function takes no parameters. It prompts the...
Python Problem 3 Write a function named enterNewPassword. This function takes no parameters. It prompts the user to enter a password until the entered password has 8-15 characters, including at least one digit. Tell the user whenever a password fails one or both of these tests.
Create a function named getCreds with no parameters that will prompt the user for their username...
Create a function named getCreds with no parameters that will prompt the user for their username and password. This function should return a dictionary called userInfo that looks like the dictionaries below: # Administrator accounts list adminList = [ { "username": "DaBigBoss", "password": "DaBest" }, { "username": "root", "password": "toor" } ] Create a function named checkLogin with two parameters: the userInfo and the adminList. The function should check the credentials to see if they are contained within the admin...
Challenge 1 – 2D Array Maker Create a function that takes in two parameters and returns...
Challenge 1 – 2D Array Maker Create a function that takes in two parameters and returns a created two-dimension array. var twoD = Make2D(<width>, <height>); Challenge 2 – Fill 2D Array Create a function that takes a single parameter and fills the 2D array with that parameter Use Cases: Fill2D(<twoD array>, <fill value>); //fills twoD twoD = fill2D(<twoD array>, <fill value>); //fills twoD, but also returns reference Challenge 3 – Make 2D Array Write a function that takes 3 parameters...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT