Im a beginner to python and my professor has assigned the following assignment:
You buy an international calling card to India. The calling card company has some
special offers.
a) If you charge your card with $5 or $10, you don’t get anything extra
b) For a $25 charge, you get $3 of extra phone time.
c) For a $50 charge, you get $8 of extra phone time
d)For a $100 charge, you get $20 extra phone time.
Write a function that asks the user for the amount he/she wants on the card, and returns
the total charge that the user gets. Note: Values other than those mentioned above are
not allowed.
Given: The problem as stated.
When designing the function, only think about the values of 5, 10, 25, 50, and 100
An additional rule: The else on the if-elif-else sequence will return the input value.
Find:
Create a function that takes no parameter, but does prompt the user for an input.
Convert that input to a number, and use a series of if-elif-else statements to find the
value of the card.
The new total value according to rules a,b,c,d is returned from the function.
Call the function from the menu and assign the return value to a variable.
Print out that variable.
I have written a function doing the following, but when I run it I cant get any of the options past a to run. What am I missing? Any help will be appreciated.
def callcard ():
print "A. For $5 or $10."
print "B. For a $25 charge, you get $3 of extra phone time."
print "C. For a $50 charge, you get $8 of extra phone time."
print "D. For a $100 charge, you get $20 extra phone time."
print " "
print " "
IOU = raw_input ("Please enter the letter for the amount you wish to enter: ")
print " "
loop=True
while (loop):
if (IOU == 'a' or 'A'):
print "You have chosen to charge $5 or $10."
amount = raw_input ("Please enter '5' for $5 or '10' for $10: ")
if (amount == '5'):
print "You have charged $5, thank you for your purchase."
elif (amount == '10'):
print "You have charged $10, thank you for your purchase."
else:
print "Incorrect value"
elif (IOU == 'b' or 'B'):
print "You have chosen to charge $25, you get $3 of extra phone time"
print " "
amount2 = raw_input ("Please confirm your purchase. Press 'Y' for yes or 'N' for no: ")
if (amount2 == 'Y' or 'y'):
print "You now have $28 of phone time, thank you for your purchase!"
print" "
elif (amount2 == 'N' or 'n'):
print "Thank you!"
print " "
else:
print "Invalid option, please try again."
elif (IOU == 'c' or 'C'):
print "You have chosen to charge $50, you will receive $8 of extra phone time."
print " "
amount3 = raw_input ("Please confirm your purchase. Press 'Y' for yes or 'N' for no: ")
if (amount3 == 'Y' or 'y'):
print "You now have $58 of phone time, thank you for your purchase!"
print " "
elif (amount3 == 'N' or 'n'):
print "Thank you!"
print " "
else:
print "Invalid option, please try again."
elif (IOU == 'd' or 'D'):
print "You have chosen to charge $100, you will receive $20 of extra phone time."
print " "
amount4 = raw_input ("Please confirm your purchase. Press 'Y' for yes or 'N' for no: ")
if (amount4 == 'Y' or 'y'):
print "You now have a total of $120 of phone time, thank you for your purchase!"
print" "
elif (amount4 == 'N' or 'n'):
print "Thank you!"
print " "
else:
print "Invalid option, please try again."
else:
print "Invalid Option"
loop=False
else:
raw_input("Done")
callcard()