for question 1 used random module to generate random numbers for height,width,length
import random
def calc(length,width,height=1):
# if height == 1 then only multiplying length and width
# else multiplying all
return (length*width,"sq ft") if height == 1 else (length*width*height,"cu ft")
def main():
# using random generating random number
length = random.randint(1,30)
width = random.randint(1,30)
height = random.randint(1,30)
# calling the functions with diff param
print(calc(length,width))
print(calc(length,width,height))
if __name__ == '__main__':
main()
# end of script
#OUTPUT your outmay diifer as it is random number
(54, 'sq ft')
(378, 'cu ft')
Please do let me know if u have any concern...
Python code You will need to make use of the random library for this homework. It...
urgent help with python. can somone code this please and show
output
QUESTION: There are a variety of games possible with a deck of cards. A deck of cards has four different suits, i.e. spades (*), clubs (*), diamonds (), hearts (), and thirteen values for each suit. Now write a function that uses list comprehension to create a deck of cards. Each element in the list will be a card, which is represented by a list containing the suit...
Questions 1. How to create a comment in python? 2. The way to obtain user input from command line 3. List standard mathematical operators in python and explain them 4. List comparison operators in python 5. Explain while loop. Give example 6. Explain for loop. Give example 7. How to create infinite loop? And how to stop it? 8. Explain a built-in function ‘range’ for ‘for’ loop 9. Explain break statement 10. Explain continue statement 11. Explain pass statement 12....
A computer program has many variables. Assuming that you need to write a program to calculate the tuition fees for the semester based on the number of units taken for the semester, What is a good variable name for storing the number of credits taken in Fall 2017? What is a bad variable name? What is a good but (unfortunately) illegal variable name? Please find the exact rule of legal variables Create a program that randomly creates a variable with...
How to write python code that is a dice rolling function that generates random numbers. The dice rolling function takes two arguments: the first argument is the number of sides on the dice and the second argument is the number of dice. The function returns the sum of the random dice rolls. For example, if I call roll dice(6,2) it might return 7, which is the sum of randomly chosen numbers 4 and 3. It somewhere along the lines of:...
given code:
assignment:
use
python to extend the given code to create an output similar to the
one in the black box
please explain the final code
import random HALMst N in = int(input('Enter Total Number of Cards: ") NM in NOON A = [] B [] E - [] D = [] E = [] for i in range(1, n+1): A.append(i) D.append(i) E.append(i) for j in range(n): 8.append(random.choice(D)) D.remove(B[5]) C.append(random.choice(E)) E.remove(C[j]) c= 0 for k in range(n): if (Brkl...cikl):...
Python Homework: - NOTE - Must not use built-in functions (other than the range() function), slice expressions, list methods (other than the append() method) or string methods in your solution. Write a function called reverse(my_list, number=-1) that takes a list and a number as parameters. The function returns a copy of the list with the first number of items reversed. Conditions: - The number parameter must be a default argument. - If the default argument for number is given in...
Please use python. You can import only: from typing import Dict, List from PIL import Image import random Questions are: --------------------------------------------------------------------------------------------------------------------------------- 1. def rotate_picture_90_left(img: Image) -> Image: """Return a NEW picture that is the given Image img rotated 90 degrees to the left. Hints: - create a new blank image that has reverse width and height - reverse the coordinates of each pixel in the original picture, img, and put it into the new picture """ ----------------------------------------------------------------------------------------------------------------------------------- 2. def...
*Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods that has the following generic methods: (1) Write the following method that returns a new ArrayList. The new list contains the nonduplicate (i.e., distinct) elements from the original list. public static ArrayList removeDuplicates(ArrayList list) (2) Write the following method that shuffles an ArrayList. It should do this specifically by swapping two indexes determined by the use of the random class (use Random rand =...
Using python The following is a modified version of the magic 8 ball. We have 20 mysterious answers to questions about anything in the universe. Each time we start this program by randomly picking 8 answers and then we randomly pick 1 from these 8 answers. This lucky answer will then be printed. This time we use the sample() function from the random library. This function randomly samples a list and return the random samples in a list. import random...
%%%%Python Question%%% Work from the template acrostic.py, which you can find on the ELMS page for this assignment. • In the Generator class, write an __init__() method with two parameters: self and the path to a text file containing one word per line. This method should read the words from the file, strip off leading and trailing whitespace, and store them in a dictionary where each key is a lower-case letter and each corresponding value is a list of words...