I'm new to programming and in my project, I'm trying to print basic dice graphics.
I'm trying to make a function that accepts two numbers from 1 to 6, and prints corresponding two dice faces next to each other. I've tried several approaches, but this is the only one that worked, and it's quite chunky:
s="+ - - - - + + - - - - +"
m1="| o o |"
m2="| o |"
m3="| o |"
m4="| o |"
m5="| |"
def dice(a,b):
if a == 1:
str1=m5
str2=m3
str3=m5
elif a == 2:
str1=m2
str2=m5
str3=m4
elif a == 3:
str1=m2
str2=m3
str3=m4
elif a == 4:
str1=m1
str2=m5
str3=m1
elif a == 5:
str1=m1
str2=m3
str3=m1
elif a == 6:
str1=m1
str2=m1
str3=m1
if b == 1:
str1=str1+" "+m5
str2=str2+" "+m3
str3=str3+" "+m5
elif b == 2:
str1=str1+" "+m2
str2=str2+" "+m5
str3=str3+" "+m4
elif b == 3:
str1=str1+" "+m2
str2=str2+" "+m3
str3=str3+" "+m4
elif b == 4:
str1=str1+" "+m1
str2=str2+" "+m5
str3=str3+" "+m1
elif b == 5:
str1=str1+" "+m1
str2=str2+" "+m3
str3=str3+" "+m1
elif b == 6:
str1=str1+" "+m1
str2=str2+" "+m1
str3=str3+" "+m1
print(s)
print(str1)
print(str2)
print(str3)
print(s)
Is there a more compact and elegant way to do this?