Given, a = 3, r = 1/2, n = 10
%r is common ratio
%n is number of terms
%a is the first term of the series
Sum = 0;
a = 3;
r = 1/2;
for i = 0 : 1 : 10;
Sum = Sum + a * r ^ i;
end
Sum
E) both C and D
Erro handling and execution paths
Answer:
endProgram = "no"
endOrder = "no"
totalBurger = 0
totalFry = 0
totalSoda = 0
total = 0
tax = 0
subtotal = 0
option = 0
burgerCount = 0
fryCount = 0
sodaCount = 0
def resetVariables():
#reset variables
totalBurger = 0
totalFry = 0
totalSoda = 0
total = 0
tax = 0
subtotal = 0
def getBurger():
global burgerCount
burgerCount += int(input("Enter the number of burgers you want: "))
totalBurger =burgerCount * .99
return totalBurger
def getFry():
global fryCount
fryCount += int(input("Enter the number of fries you want: "))
global totalFry
totalFry +=fryCount * .79
return totalFry
def getSoda():
global sodaCount
sodaCount += int(input("Enter the number of sodas you want: "))
global totalSoda
totalSoda +=sodaCount * 1.09
return totalSoda
def calcTotal():
global subtotal
subtotal += totalBurger + totalFry + totalSoda
global tax
tax += subtotal * .06
global total
total += subtotal + tax
return total
def printReceipt(total):
print("Your total is $",round(total, 2))
#Loop to run program again
while endProgram == "no":
resetVariables()
#Loop to take in order
while endOrder == "no":
print("Enter 1 for Yum Yum Burge\nEnter 2 for Grease Yum Fries\nEnter 3 for Soda Yum: \n")
option = int(input("Enter option: "))
if option == 1:
bugertotal = getBurger()
elif option == 2:
frytotal = getFry()
elif option == 3:
sodatotal = getSoda()
endOrder = input("Do you want to end your order? (Enter no to add more items): ")
mytotal = calcTotal()
printReceipt(mytotal)
endProgram = input("Do you want to end the program? (Enter no to process a new order): ")
Explanation:
The python source code displays the menu of a restaurant and the prices of each meal. The module takes multiple orders, calculates and displays the total bill of the order with tax included.