Question

In: Computer Science

I am new to python, and i used python 3. i have to make a new...

I am new to python, and i used python 3. i have to make a new program can anyone give tell mw how to do this.

A) Write a function with the name doubler. The function should take an integer parameter and return twice the value of the integer.

Test the function with the following code:

print(“Double of 6 is”,doubler(6))

The printout should be:

Double of 6 is 12

B) Write a function with the name scoreToLetter. The function should take an integer parameter and give out a letter grade according to the following grade table:

Score >=90

A

80<=score<90

B

70<=score< 80

C

Test the function with the following code:

X = 85

Print (“Your grade is”,scoreToLetter(x))

This should print:

Your grade is B

C) Write a function ‘sumOfThrows’ that takes two parameters ‘throws’ and ‘sides’. ‘sides’ should have a default values of 6. The function should return the sum from doing however many random throws specified for a die with ‘sides’ number of sides.

Test the function.

For example sumOfThrows(1,6) should show the outcome of throwing one six-sided die.

sumOfThrows(3,8) should show the outcome of throwing three dice with sides numbered 1 through 8.

sumOfThrows(2) should show the outcome of throwing two six-sided dice.

D) Move all functions to a module with name myFunctions.py. Import the myFunctions module and test all functions.

E) Submit both myFunction.py and the file with your tests named tests.py

Solutions

Expert Solution

A)

def doubler(num):
    return 2*num

print("Double of 6 is",doubler(6))

========================================================================
See The Image and write it as it




============================================================================================
B)
def scoreToLetter(score):
    if score>=90:
        return 'A'
    elif score>=80 and score<90:
        return 'B'
    elif score>=70 and score<80:
        return 'C'
  
print ("Your grade is",scoreToLetter(85))

========================================================================
See The Output





Thanks, let me know if there is any concern.


Related Solutions

I am trying to make a Risk Management tool in Python. I have it partially started....
I am trying to make a Risk Management tool in Python. I have it partially started. The scenario is that the Project Manager needs to be able to log on and enter information ( the required information is located in the code). I then need to capture that data and store it in an array with the ability to call back and make changes if necessary. Could you please help me out and explain what was done? Current code: Start...
I am trying to make a program in Python that opens a file and tells you...
I am trying to make a program in Python that opens a file and tells you how many lines, vowels, consonants, and digits there are in the file. I got the print out of lines, digits, and consonants, but the if statement I made with the vowels list isn't recognizing them. How can I make the vowels go through the if statement with the list? Am I using the wrong operator? Here is my program #Assignment Ch7-1 #This program takes...
I am confused with Python I have to write a specification for an email address. In...
I am confused with Python I have to write a specification for an email address. In one string a valid email address and the other without a valid email address. Ex: print(text_match("My teacher’s email is [email protected]")) print(text_match("My teacher has no email address"))
This is in Python, I am trying to create a new window to print the data...
This is in Python, I am trying to create a new window to print the data to screen, it prints fine in the terminal. I know this is a small segment of my code and its the only portion I am having a problem with. I was wondering if anyone can see what my problem may be. The current issue is NameError: name 'fltVal' is not defined and AttributeError: 'PressureGUI' object has no attribute 'r_count' Any help would be appreciated...
I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
I am trying to make a new code that uses functions to make it. My functions...
I am trying to make a new code that uses functions to make it. My functions are below the code. <?php */ $input; $TenBills = 1000; $FiveBills = 500; $OneBills = 100; $Quarters = 25; $Dimes = 10; $Nickels = 5; $Pennies = 1; $YourChange = 0; $input = readline("Hello, please enter your amount of cents:\n"); if(ctype_digit($input)) { $dollars =(int)($input/100); $cents = $input%100;    $input >= $TenBills; $YourChange = (int)($input/$TenBills); $input -= $TenBills * $YourChange; print "Change for $dollars dollars...
I am creating a crop watering "simulator" in Python. I have the user input an array...
I am creating a crop watering "simulator" in Python. I have the user input an array and then must compare the placement of water and crops to determine if all the crops in the array are watered. The user will either input a "w" for water or "c" for crop when creating the array. A w cell can water 8 cells around it, including itself. My end result must determine if all the crops will be watered or not. How...
Hey, I have a code that I am working on to make a garden plot calculator,...
Hey, I have a code that I am working on to make a garden plot calculator, however I am reaching an error that I cannot seem to get past. Please help. import math # GarednPlot contains all the utility functions class GardenPlot: # constructor function: Welcomes the user and sets default values def __init__(self): print("Welcome!") self.length = 0 self.radius = 0 self.depth = 0 # Sets the length of the GardenPlot and returns that length def setLength(self): self.length = float(input("Enter...
Working with Python. I am trying to make my code go through each subject in my...
Working with Python. I am trying to make my code go through each subject in my sample size and request something about it. For example, I have my code request from the user to input a sample size N. If I said sample size was 5 for example, I want the code to ask the user the following: "Enter age of subject 1" "Enter age of subject 2" "Enter age of subject 3" "Enter age of subject 4" "Enter age...
Language: C++ I am starting to make a Bigint ADT and i have the hpp file...
Language: C++ I am starting to make a Bigint ADT and i have the hpp file finished now i need to make the methods for the functions. Problem: The data type int in C++ is limited to the word size of the CPU architecture (e.g., 32 or 64 bit). Therefore you can only work with signed integers up to 2,147,483,647 (in the case of signed 32 bit). Unsigned 32 bit is still only 10 digits. Maxint for 64 is somewhat...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT