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
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
ADVERTISEMENT