# -*- coding: utf-8 -*-
"""
Created on Thu Jan  6 19:52:22 2022

@author: TANISH
"""


""" Loops """

# Loops are used when we want to perform some
# specified activity / operations a no. of times
# which may or may not be known 


# For Loop
# To be used when the no. of iterations OR
# no. of times to be executed is known

# Syntax:
# for <iterator> :
#    <block of codes>


# Eg.
# Find the PDF of exponential distribution
# Where X ~ exp(lambda = 0.55)
# For X in [0,4] with a step of 0.01


from math import exp

exp_PDF = list()
lamda = 0.55

for i in range(0,50,1):
    exp_PDF.append(lamda * exp(-lamda * i))
 
    
distributions_list = ["Gamma","Normal","Chi-sq","Students-t","F"] 
 
for i in distributions_list:
    print(i)
 
for i in range(0,5):
    print(distributions_list[i])        


# While Loop
# To be used when the no. of iterations OR
# no. of times to be executed is NOT known


# Syntax:
# while <condition> :
#    <block of codes>
#    <increment (optional)>


# Eg.
# Calculate the factorial value of a number given by user
# Using while loop

temp = 1
fact = 1
no = int(input("Please enter an positive integer to calculate its factorial value : "))

while temp <= no:
    fact = fact * temp
    temp = temp + 1    # Incremental
    
    if (temp > no):
        print("Factorial of",no,"is =",fact,sep = " ")


""" Control Statements """

# Control statements helps to change the
# Normal sequence execution in a loop

age_list = [22,23,31,32,32,33]

# Continue
# The keyword "contiue" in a loop brings the control
# back at the start of the loop

for i in age_list:
    if(i % 2 == 0):
        print("Break will be encountered")
        break;
    print(i)


# Break
# The keyword "break" in a loop brings the control
# OUT the loop

count = 0

while (not(999 in age_list)):
    count += 1
    age_list.append(int(input("Enter the Age : ")))
    
    if (count > 50):
        break;


# Continue
# The keyword "continue" in a loop brings the control
# back at the start of the loop

# Now, there is an issue with how the system
# which stores all the ages and it stores them randomly

age_list = [23,3,999,24,26]
total_fee = 0


for i in age_list:
    if (i == 999):
        continue;
        
    if(i <= 2):
        total_fee += 0
    elif (3 <= i <= 12):
        total_fee += 14
    elif (i >= 65):
        total_fee += 18
    else:
        total_fee += 23


# Break
# The keyword "break" in a loop brings the control
# OUT the loop

# Now, there is an issue with how the system
# which stores all the ages of 2 orders together


age_list = [23,3,22,999,24,26,999]
total_fee = 0


for i in age_list:
    if (i == 999):
        break;
        
    if(i <= 2):
        total_fee += 0
    elif (3 <= i <= 12):
        total_fee += 14
    elif (i >= 65):
        total_fee += 18
    else:
        total_fee += 23


# Pass
# Used for Null operations

age_list = [23,3,22,24,26]
total_fee = 0

for i in age_list:
    if (i == 999):
        pass;
        
    if(i <= 2):
        total_fee += 0
    elif (3 <= i <= 12):
        total_fee += 14
    elif (i >= 65):
        total_fee += 18
    else:
        total_fee += 23


""" Exercise """


# Q1. in previous script


# Q2.
# Calculate the factorial value of a positive number given by user
# using for loop

# Answer:

no = int(input("Enter a positive no. : "))
fact = 1

for i in range(1,no + 1):
    fact = i * fact
    
print("Factorial value for ",no," is : ",fact)
    

# Q3.
# Calculate the PDF for exponential distribution
# Where X ~ exp(lambda = 0.55)
# For all x where PDF is < 0.001, i.e f(x) < 0.001
# don't include those values of "x"

# Give the value of "x" at which f(x) >= 0.001

# Take increments of x to be 0.01,
# i.e 0, 0.01, 0.02, ...

# Answer:

from math import exp

exp_PDF = list()
lamda = 0.55
temp = 10
x = 0
dummy = list()


while (temp >= 0.001):
    exp_PDF.append((lamda * (exp(-(lamda * x)))))
    dummy.append(x)
    x = round(x + 0.01,2)   # Incremental
    temp = exp_PDF[-1]      # Update temp with latest PDF value
                 
print("The value of x is :",dummy[0],"to",dummy[-2])


# Q4.
# A drama theatre determines the price of the ticket based on
# the age of the customer.
# Customer with 2 years of age and less are admitted without charge. 
# Children between 3 and 12 years of age cost $14.00. 
# Seniors aged 65 years and over cost $18.00. 
# Admission for all other guests is $23.00. 

# The cashier wants to automate the process from the user end,
# Such that the user will enter one age at a time. 
# The user will enter a 999 to indicate that there are 
# no more people in the group. 

# Then your program should display the total fee
# for the group and take a confirmation before 
# printing the bill

# Answer:

# Take age = 23,24,31,31,1
    
    
age_list = []

while (not(999 in age_list)):
    age_list.append(int(input("Enter the age of the guest : ")))
    
    
age_list.remove(999)

total_fee = 0

for i in age_list:
    if(i <= 2):
        total_fee = total_fee + 0   # total_fee += 0
    elif (3 <= i <= 12):
        total_fee += 14
    elif (i >= 65):
        total_fee += 18
    else:
        total_fee += 23

print("Total guest(s) : ",len(age_list))
print("Tota Bill : ",total_fee)


if(str(input("Enter: Y = Confirm | N = Decline : ")) == "Y"):
    print("Total guest(s) : ",len(age_list))
    print("Tota Bill : ",total_fee)
else:
    print("Order Declined")
    
