Question

Write a function that will take in a number (from 1-6) through the parameter, and will display the appropriate ASCII depiction of a dice face with pips. Then create a program that generates a random number 1-6 and calls your Function to display the random dice face.

The ASCII dice should look like one of the following examples: I* 11* *1

Using python 3.6 to solve this problem.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
import random 
def printDice(n):
    print('+-----+')

    # second row
    if n == 1:
        print('|' + ' '*5 +'|')
    elif n == 2 or n == 3:
        print('|*' + ' '*4 +'|')
    else:
        print('|*' + ' '*3 +'*|')

    # third row
    if n == 1 or n == 3 or n == 5:
        print('|' + ' '*2 + '*' + ' '*2 +'|')
    elif n == 2 or n == 4:
        print('|' + ' '*5 +'|')
    else:
        print('|*' + ' '*3 +'*|')

    # fourth row
    if n == 1:
        print('|' + ' '*5 +'|')
    elif n == 2 or n == 3:
        print('|' + ' '*4 +'*|')
    else:
        print('|*' + ' '*3 +'*|')

    print('+-----+\n\n')

for _ in range(10):
    printDice(random.randint(1, 6))

īn.py B っ saved import random def printDice(n): print() # second row print(* print( 4 I) print(I * + *3 +*1) elif n == 2 or n== 3: else: # third row print(5) else: print(3 *) # fourth row If n 1: print(5) print( + *4 + 치 . ) print(I*, + . .3 +*I. else: print(nn) for in range (10): printDice(random.randint (1, 6))


Hi. please find the answer above.. In case of any doubts, please ask in comments. If the answer helps you, please upvote. I am in great need of upvotes. Thanks!

Add a comment
Know the answer?
Add Answer to:
Write a function that will take in a number (from 1-6) through the parameter, and will...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a void function that generates a random number from 0 to 1 with two decimal...

    Write a void function that generates a random number from 0 to 1 with two decimal digits and uses a proper parameter to return it. Write a C program that calls the function and displays the return value.

  • Python: Write a func that will create a list of random numbers. The function will take...

    Python: Write a func that will create a list of random numbers. The function will take in two parameters. The first parameter specifies how many values to generate and the second parameter is the highest random # (2 is the minimum) that the func generates. To get the random numbers, you may use this line of code: y = random.randint (2,max), where max is the highest possible random #, INCLUSIVE.

  • Write a python function named displayFizzBuzz that takes a number as a parameter and DISPLAYS the...

    Write a python function named displayFizzBuzz that takes a number as a parameter and DISPLAYS the appropriate FizzBuzz value for that number. Test this function on all of the numbers between 1 and 100000. Submit the code and a screenshot of the program running in Linux

  • DATA PROGRAMMING: PYTHON Be sure to use sys.argv NOT input. Write a program and create a...

    DATA PROGRAMMING: PYTHON Be sure to use sys.argv NOT input. Write a program and create a function called inch2cm that takes one number in inches as a parameter, converts it to the centimeters and prints the result. The program output is shown below. Input: 14 Output: 14 inches = 35.56 centimeter Write a program and create the following functions: shapes(): takes the shape name and a number as parameters, and calls the proper function to calculate the area. areaCircle(): take...

  • Write a Python program with a function that will take as input from the user the...

    Write a Python program with a function that will take as input from the user the temperature in Celsius and will convert and display temperature values in both Fahrenheit and Celsius, using the equation: F = (C ∗ 9/5)+ 32 Note: below is what a sample input line to your program should look like and the resulting output. User input lines always start with >>>. This convention will be used for all of the problem sets. >>>Enter temperature in Celsius:...

  • question 2 in C programming please PE-05b-01 (Six-sider) write a counter-controlled program that prompts the user...

    question 2 in C programming please PE-05b-01 (Six-sider) write a counter-controlled program that prompts the user to enter the number of times n to roll a six-sided die. The program should print to the screen the iteration of the loop and result for each roll 1 ) How many times would you like to roll? 3 roll 6 6 5 1 2) PE 05b 02 (Flash Cards) Write a counter-controlled program that creates addition problems for an elementary kid to...

  • In Python Complete the function powersOf5(). Have the function take a parameter n and return a...

    In Python Complete the function powersOf5(). Have the function take a parameter n and return a list of the first n powers of 5. One way to calculate powers of 5 is by starting with 1 and then multiplying the previous number by 5. Examples: powersOf5( 1 ) returns [1] powersOf5( 2 ) returns [1, 5] powersOf5( 3 ) returns [1, 5, 25] powersOf5( 6 ) returns [1, 5, 25, 125, 625, 3125] powersOf5( 10 ) returns [1, 5, 25,...

  • Look at the following function definition: def my_function(x, y): return x[y] a. Write a statement that...

    Look at the following function definition: def my_function(x, y): return x[y] a. Write a statement that calls this function and uses keyword arguments to pass ‘testing’ into x and 2 into y. b. What will be printed when the function call executes? 6. Write a statement that generates a random number in the range I'm using python to solve this this is what i did def main():      result= my_function(x='testing', y=2)      print(result) def my_function(x,y):      return x[y] main()

  • In Python, Complete the extraCreditTotal() function to take a list of grades as a parameter and...

    In Python, Complete the extraCreditTotal() function to take a list of grades as a parameter and return the total number points above 100. Examples: extraCreditTotal( [101, 83, 107, 90] ) returns 8 (because 1 + 0 + 7 + 0 is 8) extraCreditTotal( [89, 113, 95] ) returns 13 extraCreditTotal( [89, 73, 96, 97, 99, 100] ) returns 0

  • (c++) Write a program that generates a random number between 1 and 100 and asks the...

    (c++) Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. Be sure that your program...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT