In: Computer Science
Write a program in python that will produce this outcome.
Project 2: Developed by Yourname
0. Exit
1. Print a Diamond
2. Print a Number Pattern
3. Print a cost table
Enter your choice:
1
Enter the length (an even number between 0 and 20): -1
Enter the length (an even number between 0 and 20): 3
Enter the length (an even number between 0 and 20): 22
Enter the length (an even number between 0 and 20): 10
Enter the char used left to the diamond: *
Enter the char used to fill the diamond: T
\TTTTTTTT/
*\TTTTTT/
**\TTTT/
***\TT/
****\/
****/\
***/TT\
**/TTTT\
*/TTTTTT\
/TTTTTTTT\
0. Exit
1. Print a Diamond
2. Print a Number Pattern
3. Print a cost table
Enter your choice:
3
Enter the maximum quantity (between 1 and 9): 0
Do you want horizontal (item\qnty) table (Yes or No): Yes
Cost Table
Item\Qty
Beans
Rice
Banana
Ice
Tea
Bread
Orange
Sugar
0. Exit
1. Print a Diamond
2. Print a Number Pattern
3. Print a cost table
Enter your choice:
3
Enter the maximum quantity (between 1 and 9): 5
Do you want horizontal (item\qnty) table (Yes or No): No
Cost Table
Qty\Item Beans Rice Banana Ice Tea Bread Orange Sugar
1 3.25 4.31 6.88 3.30 5.25 4.89 6.32 2.25
2 6.50 8.62 13.76 6.60 10.50 9.78 12.64 4.50
3 9.75 12.93 20.64 9.90 15.75 14.67 18.96 6.75
4 13.00 17.24 27.52 13.20 21.00 19.56 25.28 9.00
5 16.25 21.55 34.40 16.50 26.25 24.45 31.60 11.25
0. Exit
1. Print a Diamond
2. Print a Number Pattern
3. Print a cost table
Enter your choice:
3
Enter the maximum quantity (between 1 and 9): 4
Do you want horizontal (item\qnty) table (Yes or No): Yes
Cost Table
Item\Qty 1 2 3 4
Beans 3.25 6.50 9.75 13.00
Rice 4.31 8.62 12.93 17.24
Banana 6.88 13.76 20.64 27.52
Ice 3.30 6.60 9.90 13.20
Tea 5.25 10.50 15.75 21.00
Bread 4.89 9.78 14.67 19.56
Orange 6.32 12.64 18.96 25.28
Sugar 2.25 4.50 6.75 9.00
0. Exit
1. Print a Diamond
2. Print a Number Pattern
3. Print a cost table
Enter your choice:
0
Thank you for using this program. Bye.
while True:
print("0. Exit\n1. Print a Diamond\n2.Print a Number
Pattern\n3.Print a cost table\nEnter your choice:")
c=int(input()) #read the choice
if c==0: #if choice=0 break the loop
print("Thank you for using this program. Bye.")
break
elif c==1: #c=1 for print the diamond
print("Enter the length (an even number between 0 and
20):",end="")
ch=int(input()) #read the integer for no of lines
while ch<=0 or ch>20: #if ch is not between 0 and 20 ,repeat
the loop
print("Enter the length (an even number between 0 and
20):",end="")
ch=int(input())
print("Enter the char used left to the diamond:",end="")
a=input()
print("Enter the char used to fill the diamond:",end="")
b=input()
k=ch #k represents number of symbols represent diamond
for i in range(ch//2): #loop for half of diamond
print(a*i+'\\'+b*(k-2)+'/')
k=k-2 #k decrements by 2 for every iteration upto half of the
diamond
for j in range(ch//2,0,-1): #loop for remianing half of
diamond
print(a*(j-1)+'/'+b*k+'\\')
k=k+2 #k increments by 2 for every iteration upto half of the
diamond
elif c==2:
pass #in the quetion, they didnt mention the number pattern
example.
elif c==3:
#items list
items=["Beans", "Rice", "Banana", "Ice", "Tea", "Bread", "Orange",
"Sugar"]
#price list
lt=[3.25, 4.31, 6.88, 3.30, 5.25, 4.89, 6.32, 2.25]
print("Enter the maximum quantity (between 1 and 9):
",end="")
q=int(input())
print("Do you want horizontal (item\qnty) table (Yes or No):
",end="")
r=input()
print("Cost Table")
if r=="Yes":
print("Item/Qnty",end=" ")
for i in range(1,q+1):
print(i,end=" ") #print quantities
print()
for i in range(len(items)):
print(items[i],end=" ") #print items
for j in range(1,q+1):
print("{0:.2f}".format(lt[i]*j),end=" ") #cost of items
print()
elif r=="No":
print("Qnty/Item",end=" ")
for i in items:
print(i,end=" ") #print items
print()
for j in range(1,q+1):
print(j,end=" ") #print quantities
for k in range(len(lt)):
print("{0:.2f}".format(lt[k]*j),end=" ") #print cost of items
print()
output: