Storing a Function - python

import sys
print("Hello I am FoodBot, welcome to Fire n' Fusion. Please choose your item in each category.")
print("When I ask for your choices enter the code of the menu item.")
menuname= str(input("What is the name you would like your order placed under:"))
questioninput= int(input("Would like to eat here or would you like your order to-go? Enter 1 for eating here and 2 if you would like your meal to-go:"))
if questioninput < 1 or questioninput > 2:
sys.exit("Sorry there was an error in your input. Please retry!")
print("Here are the appetizers...")
print("-------------------------------")
print("Honey Chilli Potatoes($3.20) - Use Code 1")
print("Paneer Lettuce Wraps($5.10) - Use Code 2")
print("Mini Chicken Tamales($3.55) - Use Code 3 ")
print("Fiery Chicken Meatballs($5.99) - Use Code 4")
print("Enter 5 for Nothing")
appetizerinput = int(input("Enter what you would like in APPETIZERS[Code = 1-5]: "))
if appetizerinput == 1:
item_price_app = 3.20
elif appetizerinput == 2:
item_price_app = 5.10
elif appetizerinput == 3:
item_price_app = 3.55
elif appetizerinput == 4:
item_price_app = 5.99
elif appetizerinput == 5:
item_price_app = 0.00
elif appetizerinput < 1 or appetizerinput > 5:
sys.exit("Sorry there was an error in your input. Please retry!")
print("Here are the Entrees...")
print("-------------------------------")
print("Gobi Munchurian($7.21) - Use Code 6")
print("Grilled Veggie Skewers($5.33) - Use Code 7")
print("Paneer Kathi Rolls($7.79) - Use Code 8")
print("Lemon and Ginger Chicken($8.60) - Use Code 9")
print("Hot Chicken Lasagna($6.45) - Use Code 10")
print("Prisha's Favorite Chicken n'Cheese Enchiladas ($7.84) - Use Code 11")
print("Enter 12 for Nothing")
entreeinput = int(input("Enter what you would like in ENTREES [Code 6-12]:"))
if entreeinput == 6:
item_price_ent = 7.21
elif entreeinput == 7:
item_price_ent = 5.33
elif entreeinput == 8:
item_price_ent = 7.79
elif entreeinput == 9:
item_price_ent = 8.60
elif entreeinput == 10:
item_price_ent = 6.45
elif entreeinput == 11:
item_price_ent = 7.84
elif entreeinput == 12:
item_price_ent = 0.00
elif entreeinput < 6 or entreeinput > 12:
sys.exit("Sorry there was an error in your input. Please retry!")
print("Here are the Choices for Bread and Rice...")
print("-------------------------------")
print("Cumin Rice($2.25) - Use Code 13")
print("Egg Friedrice($3.25) - Use Code 14")
print("Plain Kulcha($1.50) - Use Code 15")
print("AlooKulcha($2.25) - Use Code 16")
print("Enter 17 for Nothing")
breadandriceinput = int(input("Enter what you would like in BREAD AND RICE [Code 13-17]:"))
if breadandriceinput == 13:
item_price_brice = 2.25
elif breadandriceinput == 14:
item_price_brice = 3.25
elif breadandriceinput == 15:
item_price_brice = 1.50
elif breadandriceinput == 16:
item_price_brice = 2.25
elif breadandriceinput == 17:
item_price_brice = 0.00
elif breadandriceinput < 13 or breadandriceinput > 17:
sys.exit("Sorry there was an error in your input. Please retry!")
print("Here are the Choices for Desserts...")
print("-------------------------------")
print("Arabic King-Sweets($3.99) - Use Code 18")
print("Coconut Fried IceCream($2.50) - Use Code 19")
print("Supreme Vanilla Fudge($3.75) - Use Code 20")
print("Enter 21 for Nothing")
dessertinput = int(input("Enter what you would like in DESSERTS [Code 18-21]:"))
if dessertinput == 18:
item_price_des = 3.99
elif dessertinput == 19:
item_price_des = 2.50
elif dessertinput == 20:
item_price_des = 3.75
elif dessertinput == 21:
item_price_des = 0.00
elif dessertinput < 18 or dessertinput > 21:
sys.exit("Sorry there was an error in your input. Please retry!")
print("Here are the Choices for Drinks...")
print("-------------------------------")
print("Chai($1.00) - Use Code 22")
print("Cookies n' Cream Milkshake($2.50) - Use Code 23")
print("Bottle of Water($1.25) - Use Code 24")
print("FountainDrink($1.50) - Use Code 25")
print("Enter 26 for Nothing")
drinkinput = int(input("Enter what you would like in DRINKS [Code 22-26]:"))
if drinkinput == 22:
item_price_dri = 1.00
elif drinkinput == 23:
item_price_dri = 2.50
elif drinkinput == 24:
item_price_dri = 1.25
elif drinkinput == 25:
item_price_dri = 1.50
elif drinkinput == 26:
item_price_dri = 0.00
elif drinkinput < 22 or drinkinput > 26:
sys.exit("Sorry there was an error in your input. Please retry!")
sauceinput = str(input("Would you like a sauce platter with your meal(enter Yes or No)FREE!:"))
def mybill():
print(" ")
print(" ")
print(" ")
print(" ")
print(" -----Fire n' Fusion------")
if questioninput == 1:
print("Meal:EATING IN THE RESTARAUNT")
elif questioninput == 2:
print("Meal:TO-GO ORDER")
if appetizerinput == 1:
print("Honey Chilli Potatoes: " + " $3.20")
elif appetizerinput == 2:
print("Paneer Lettuce Wraps: " + " $5.10")
elif appetizerinput == 3:
print("Mini Chicken Tamales: " + " $3.55")
elif appetizerinput == 4:
print("Fiery Chicken Meatballs: " + " $5.99")
if entreeinput == 6:
print("Gobi Munchurian: " + " $7.21")
elif entreeinput == 7:
print("Grilled Veggie Skewers: " + " $5.33")
elif entreeinput == 8:
print("Paneer Kathi Rolls: " + " $7.79")
elif entreeinput == 9:
print("Lemon and Ginger Chicken: " + " $8.60")
elif entreeinput == 10:
print("Hot Chicken Lasagna: " + " $6.45")
elif entreeinput == 11:
print("Prisha's Favorite Chicken n' Cheese Enchiladas:" + "$7.84")
if breadandriceinput == 13:
print("Cumin Rice: " + " $2.25")
elif breadandriceinput == 14:
print("Egg Fried Rice: " + " $3.25")
elif breadandriceinput == 15:
print("Plain Kulcha: " + " $1.50")
elif breadandriceinput == 16:
print("Aloo Kulcha: " + " $2.25")
if dessertinput == 18:
print("King-Sweets: " + " $3.75")
elif dessertinput == 19:
print("Coconut Fried Ice Cream: " + " $2.50")
elif dessertinput == 20:
print("Supreme Vanilla Fudge: " + " $3.75")
if drinkinput == 22:
print("Chai: " + " $1.00")
elif drinkinput == 23:
print("Cookies n' Cream Milkshake:" + "$2.50")
elif drinkinput == 24:
print("Bottle of Water: " + " $1.25")
elif drinkinput == 25:
print("Fountain Drink: " + " $2.50")
totalcost = round(item_price_app + item_price_ent + item_price_brice + item_price_des + item_price_dri, 2)
print("Order Name:" + menuname)
print(" Total:" + str (totalcost))
taxresult = round(totalcost*0.0775, 2)
print(" Tax:" + str (taxresult))
mysubtotal = round(totalcost+taxresult, 2)
print(" Subtotal:" + str (mysubtotal))
print("-------HEAD TO THE CASHIER TO PAY-------")
print(" --Thank you For Choosing Fire n' Fusion--")
print(" *********ENJOY YOUR MEAL!*********" )
mybill()
This above is my code. You will notice that I have a function called mybill in it. I need someone to explain to me how to store the output of the bill in a file so the restaurant manager can go back, use user input to enter a date, and see all the bills that were from that specific date he entered. I do not need my whole code to be stored, I only need the output of each of the times a bill is printed to be stored by the date it was printed. Thanks.

You could use python's datetime package for the current date and time
import datetime
now = datetime.datetime.now()
See here for additional information
And then use python's built in file management stuff to read/write to/from a csv file
receipt_file= open("Receipts.csv", 'a')
receipt_file.write(str(now.year) +',' + str(now.month) + ',' str(now.day) + ',' + str(total_cost))
receipt_file.close()
And when you read it back in to sort by user input, you could even split by year, month, and day
receipt_file= open("Receipts.csv", 'r')
for line in receipt_file.readlines():
year = line.split(',')[0]
month = line.split(',')[1]
# And so on - maybe even add list of receipts found with given criteria?

There are probably many options to do this, depending on how fancy you want to be and how adept you are at programming. A database would probably be ideal, but you could use a simple dictionary.
Using a dictionary with date keys:
sales = {date1: {sale1:[], sale2:[]..., date2: {sale1:[], sale2:[]...}
If you have a dictionary stored as a pickle, you could work this into your code (modifying as needed).
import pickle
import datetime as dt
# define today's date
heute = dt.date.today()
with open('data.p', 'rb') as fid:
data = pickle.load(fid)
# when adding data to your dictionary
if heute not in data:
data[heute] = {}
# add sale
item = 'soup'
cost = 5.60
quantity = 4
salenum = 'sale' + str(len(data[heute]) + 1)
data[heute][salenum] = {}
data[heute][salenum][item] = {}
data[heute][salenum][item]['cost'] = cost
data[heute][salenum][item]['quantity'] = quantity
# store data to pickle
with open('data.p', 'wb') as fid:
pickle.dump(data, fid)
When you want to get sales for each day:
with open('data.p', 'rb') as fid:
data = pickle.load(fid)
# specify date of interest
doi = dt.date(2017, 1, 1)
if doi not in data:
print('No sales today!')
else:
for sale in sorted(data[doi]):
for item in data[doi][sale]:
print(item + 'x' + data[doi][sale][item]['quantity'] + ' # $' + data[doi][sale]['cost'] + ' each')
This is just a general outline of something you could do with a dictionary, and should be easily modifiable for your needs.
NOTE
This code is not ready to run (don't copy/paste), it is just an example of one option that will work (tweaking required).

You can open a simple text file with append functionality and write all the strings one by one in bill and store that bill with some naming convention so that you can open that bill again with your code in future by passing that name string (i.e the bill date).
To write your output in code to bill text file you can do the following:
You have multiple print statements in a method. You can assign those to a string and print them in terminal as well copy them to your text file.
def mybill():
with open("bill.txt", "a") as mybillfile:
# use following structure for every print statement
str = " -----Fire n' Fusion------"
myfile.write(str)
print(str)

Related

Keep receiving "TypeError: unsupported operand type(s) for *: 'function' and "float' . I know its probably a simple mistake but I cant find it

Keep getting the TypeError of an unsupported operand. I believe it to be when calling the active_met_rate but I'm not sure what needs to be corrected.
def bmr_calc():
weightKg = int(input("Weight: "))
heightInc = int(input("Height: "))
age = int(input("Age: "))
gender = input("Are you a (m)ale or (f)emale:").lower()
if gender == "m":
base_met_rate = int((66.47 + (6.24*weightKg) + (12.7*heightInc) - (6.76*age)))
elif gender == "f":
base_met_rate = int(((4.54*weightKg) + (15.88*heightInc) - (5*age) - 161))
print("Your Basal Metabolic Rate is " + str(bas_met_rate) + " kcals")
return base_met_rate
def amr_calc(base_met_rate):
frequency = int(input("How many days do you work out?: "))
if frequency == 0:
act_fact = 1.2
elif frequency == 1:
act_fact = 1.2875
elif frequency == 2:
act_fact = 1.375
elif frequency == 3:
act_fact =1.41875
elif frequency == 4:
act_fact = 1.4625
elif frequency == 5:
act_fact = 1.55
elif frequency == 6:
act_fact = 1.6375
elif frequency == 7:
act_fact = 1.725
active_met_rate = int(base_met_rate*act_fact)
print("Your Active Metabolic Rate is " + str(active_met_rate) + " kcals")
return(active_met_rate)
base_met_rate = bmr_calc
active_met_rate = amr_calc(base_met_rate)
bmr_calc is a function that returns the Base Metabolic Rate. You need to call it, like this: base_met_rate = bmr_calc(). When you do that, then you can pass base_met_rate, which is a float, to amr_calc.

Simple coinflip terminal game won't update variable

I am trying to code a simple coinflip game with a gambling function. My issue is, whenever it runs, it doesn't update the balance variable. Any suggestions?
import random
balance = 10
win = "Congrats! You have won "
lose = "That's too bad, you lost this time! You now have "
start_game = False
while True:
choice = input("Please use one of these commands 'flip', 'balance', or 'end game'. ")
if choice == "flip":
start_game = True
break
elif choice == "balance":
print(balance)
elif choice == "end game":
break
else:
print("Please use one of the listed commands!")
if start_game == True:
while True:
result = random.randint(1,2)
if result == 1:
result = True
elif result == 2:
result = False
gamble_amount = input("How much would you like to flip? You have " + str(balance) + " coins. ")
if str(gamble_amount) == "balance":
print(balance)
elif int(gamble_amount) <= int(balance) and result == True:
int(gamble_amount) * 2
int(balance) + int(gamble_amount)
print(win + str(gamble_amount) + "!" + " You now have " + str(balance) + "!")
elif int(gamble_amount) <= int(balance) and result == False:
int(balance) - int(gamble_amount)
print(lose + str(balance) + " coins!")

How do I stop my code from printing the extra question?

How do I stop from printing an extra input line? I'm new with python/coding
class1 = "Math"
class2 = "English"
class3 = "PE"
class4 = "Science"
class5 = "Art"
def get_input(className):
classInput = raw_input("Enter the score you received for " + className + ": ")
while int(classInput) >= 101 or int(classInput) <= -1:
print "Needs to be in the range 0 to 100"
classInput = raw_input("Enter the score you received for " + className + ": ")
return int(classInput)
def get_letter_grade(grade):
if grade >= 93:
return"A"
elif grade >= 90:
return"A-"
elif grade >= 87:
return"B+"
elif grade >= 83:
return"B"
elif grade >= 80:
return"B-"
elif grade >= 77:
return"C+"
elif grade >= 73:
return"C"
elif grade >= 70:
return"C-"
elif grade >= 67:
return"D+"
elif grade >= 63:
return"D"
elif grade >= 60:
return"D-"
else:
return"F"
print "Your " + class1 + " score is " + str(get_input(class1)) + ", you got a " +
get_letter_grade(get_input(class1))
Prints out:
Enter the score you received for Math: 85
Enter the score you received for Math: 85
Your Math score is 85, you got a B
Inside your print, you call get_input() method twice:
print "Your " + class1 + " score is " + str(get_input(class1)) + ", you got a " +
get_letter_grade(get_input(class1))
What you need to do is store your score by calling get_input() method once and use the stored value in print method:
score = get_input(class1)
print("Your " + class1 + " score is " + str(score) + ", you got a " +
get_letter_grade(score))
I would separate out your calls to get_input from your print statement, not just here, but generally.
score = str(get_input(class1))
print "Your " + class1 + " score is " + score + ", you got a " +
get_letter_grade(score)
As a rule of thumb, any user input should almost always be immediately stored in a variable to be manipulated and/or used later.

python blackjack ace problem which breaks my code

I currently am making a blackjack python minigame, where a player plays until he gets a blackjack or stands and returns the value of his deck. This game does not play against a dealer and instead just uses his hands as a score. My problem is, I cannot figure out a way to make aces go from 11 to 1 without looping and breaking the program. Here is my code:
import random
def play():
output = "Your hand: "
player = []
total=0
count = 0
while len(player) != 2:
card = random.randint(1,52)
if card <= 4:
output += "A "
total += 11
player.append("A")
elif card <= 8:
output+="2 "
total+=2
player.append("2")
elif card <= 12:
output+="3 "
total+=3
player.append("3")
elif card <= 16:
output+="4 "
total+=4
player.append("4")
elif card <= 20:
output+="5 "
total+=5
player.append("5")
elif card <= 24:
output+="6 "
total+=6
player.append("6")
elif card <= 28:
output+="7 "
total+=7
player.append("7")
elif card <= 32:
output+="8 "
total+=8
player.append("8")
elif card <= 36:
output+="9 "
total+=9
player.append("9")
elif card <= 40:
output+="10 "
total+=10
player.append("10")
elif card <= 44:
output+="J "
total+=10
player.append("J")
elif card <= 48:
output+="Q "
total+=10
player.append("Q")
elif card <= 52:
output+= "K "
total+=10
player.append("K")
if len(player) == 2:
print(f"{output} ({total}) ")
while len(player) >= 2:
action_taken = input("Would you like to 'hit' or 'stand': ")
if action_taken == "hit":
card = random.randint(1,52)
if card <= 4:
output += "A "
total += 11
player.append("A")
elif card <= 8:
output+="2 "
total+=2
player.append("2")
elif card <= 12:
output+="3 "
total+=3
player.append("3")
elif card <= 16:
output+="4 "
total+=4
player.append("4")
elif card <= 20:
output+="5 "
total+=5
player.append("5")
elif card <= 24:
output+="6 "
total+=6
player.append("6")
elif card <= 28:
output+="7 "
total+=7
player.append("7")
elif card <= 32:
output+="8 "
total+=8
player.append("8")
elif card <= 36:
output+="9 "
total+=9
player.append("9")
elif card <= 40:
output+="10 "
total+=10
player.append("10")
elif card <= 44:
output+="J "
total+=10
player.append("J")
elif card <= 48:
output+="Q "
total+=10
player.append("Q")
elif card <= 52:
output+= "K "
total+=10
player.append("K")
if len(player) >= 2 and total <=21:
print(f"{output} ({total}) ")
if total > 21:
if "A" in player: #Ask why ace always messes up
if count < 1:
count +=1
total-=10
print(f"{output} ({total}) ")
if player.count("A") > 1:
total -= 10
print(f"{output} ({total}) ")
else:
print(f"{output} ({total}) ")
print("BUST!")
return total
if action_taken == "stand":
return total
if action_taken != "hit" or "stand":
print("Enter a valid input ('hit' or 'stand') ")
play()
if "A" in player will always be True once there's an ace in the deck, and so you never get to the else where you print "BUST!" and return, so the loop just continues. You can do something like incremeting count for every ace in the deck and then change the ace part to be:
if total > 21:
player_aces = player.count("A") # How many aces the player has
if player_aces != count: # Meaning there are aces that weren't checked
for _ in range(player_aces - count):
total -= 10 # Could also be simplified to: total -= 10 * (player_aces - count)
count = player_aces
print(f"{output} ({total}) ")
else:
print(f"{output} ({total}) ")
print("BUST!")
return total
Also, if action_taken != "hit" or "stand" doesn't check that action_taken is not "hit" and not "stand". An or treats both its inputs as bool values and returns whether at least one is True. The != operator has precedence over or, so the line is actually if (action_taken != "hit") or "stand". The left part of that does what it's supposed to do, but then the right part evaluates "stand" as a bool, and in python every non-empty string is evaluated as True. So the right expression is always True, and so is the or - and the program will always enter the if statement.
You probably want: if action_taken != "hit" and action_taken != "stand".
There were a coupe of issues that I have fixed. I have created a counter for the number of Aces, this allows us to count how many times we can reduced the total by - otherwise we just keep removing 10.
Also the indentation of the last else statement needed moving out.
import random
def play():
output = "Your hand: "
player = []
total=0
count = 0
reducedA = 0
while len(player) != 2:
card = 1
#card = random.randint(1,52)
if card <= 4:
output += "A "
total += 11
reducedA+=1
player.append("A")
elif card <= 8:
output+="2 "
total+=2
player.append("2")
elif card <= 12:
output+="3 "
total+=3
player.append("3")
elif card <= 16:
output+="4 "
total+=4
player.append("4")
elif card <= 20:
output+="5 "
total+=5
player.append("5")
elif card <= 24:
output+="6 "
total+=6
player.append("6")
elif card <= 28:
output+="7 "
total+=7
player.append("7")
elif card <= 32:
output+="8 "
total+=8
player.append("8")
elif card <= 36:
output+="9 "
total+=9
player.append("9")
elif card <= 40:
output+="10 "
total+=10
player.append("10")
elif card <= 44:
output+="J "
total+=10
player.append("J")
elif card <= 48:
output+="Q "
total+=10
player.append("Q")
elif card <= 52:
output+= "K "
total+=10
player.append("K")
if len(player) == 2:
print(f"{output} ({total}) ")
while len(player) >= 2:
action_taken = input("Would you like to 'hit' or 'stand': ")
if action_taken == "hit":
card = random.randint(1,52)
if card <= 4:
output += "A "
total += 11
player.append("A")
reducedA += 1
elif card <= 8:
output+="2 "
total+=2
player.append("2")
elif card <= 12:
output+="3 "
total+=3
player.append("3")
elif card <= 16:
output+="4 "
total+=4
player.append("4")
elif card <= 20:
output+="5 "
total+=5
player.append("5")
elif card <= 24:
output+="6 "
total+=6
player.append("6")
elif card <= 28:
output+="7 "
total+=7
player.append("7")
elif card <= 32:
output+="8 "
total+=8
player.append("8")
elif card <= 36:
output+="9 "
total+=9
player.append("9")
elif card <= 40:
output+="10 "
total+=10
player.append("10")
elif card <= 44:
output+="J "
total+=10
player.append("J")
elif card <= 48:
output+="Q "
total+=10
player.append("Q")
elif card <= 52:
output+= "K "
total+=10
player.append("K")
if len(player) >= 2 and total <=21:
print(f"{output} ({total}) ")
if total > 21:
if "A" in player: #Ask why ace always messes up
if count < 1:
count +=1
total-=10
print(f"{output} ({total}) ")
if player.count("A") > 1 and reducedA:
total -= 10
reducedA -= 1
print(f"{output} ({total}) ")
else:
print(f"{output} ({total}) ")
print("BUST!")
return total
else:
print(f"{output} ({total}) ")
print("BUST!")
return total
if action_taken == "stand":
return total
if action_taken != "hit" or action_taken != "stand":
print("Enter a valid input ('hit' or 'stand') ")
play()

Reducing the number of conditionals in a small python script [duplicate]

This question already has answers here:
Date Ordinal Output?
(14 answers)
Closed 6 years ago.
I have been developing a small program.
It works perfectly how it is but I want to make the code a bit smaller.
import time, math
name= input("Enter Your Name: ")
age= int(input("Enter Your Age: "))
end= "th"
if age == 3 or age == 13 or age == 23 or age == 33 or age == 43 or age == 53 or age == 63 or age == 73 or age == 83 or age == 93:
end= "rd"
if age == 2 or age == 22 or age == 32 or age == 42 or age == 52 or age == 62 or age == 72 or age == 82 or age == 92:
end= "nd"
print ("Your Name Is "+ name + ", You Are " + str(age) + " Years Old.")
print ("Hi " + name + ", Happy " + str(age) + end + " birthday!")
time.sleep(5)
I would like to have an easier way to change the 'end' to other values without having to write them all, can I have it start at 3 then do it for everything 10 more than three.
Use the modulo operator:
if age % 10 == 3:
end = "rd"
elif age % 10 == 2:
end = "nd"
Or use a dict:
ends = {2: "nd", 3: "rd"}
end = ends[age % 10]
You can also use a default:
ends = {1: "st", 2: "nd", 3: "rd"}
end = ends.get(age % 10, "th)
Extract the digit at tenth's place. Then it's straightforward. Though this question belongs to the codereview counterpart of SO.
import time, math
name= input("Enter Your Name: ")
age= int(input("Enter Your Age: "))
tenth_place = age % 10
if tenth_place == 3:
end = "rd"
elif tenth_place == 2:
end = "nd"
else:
end = "th"
print ("Your Name Is "+ name + ", You Are " + str(age) + " Years Old.")
print ("Hi " + name + ", Happy " + str(age) + end + " birthday!")
time.sleep(5)
if age in range(3,93,10) :
end = "rd"
You can try this:
if int(age[-1]) == 3:
end= "rd"
if int(age[-1]) == 2:
end= "nd"
Might not be shorter necessarily, but it works (and keeps 12th and 13th proper).
import time, math
name = input("Enter Your Name:")
age = int(input("Enter Your Age:"))
end = "th"
# initializing age lists
list1 = []
list2 = []
# filling list1 with ages 3-93
for i in range(0,10):
list1.append(10*i+3)
# filling list2 with ages 2-92
for i in range(0,10):
list2.append(10*i+2)
# if block to include correct suffix
for ages in list1:
if ages == 13:
end = end;
elif ages == age:
end = "rd"
for ages in list2:
if ages == 12:
end = end
elif ages == age:
end = "nd"
print ("Your Name Is "+ name + ", You Are " + str(age) + " Years Old.")
print ("Hi " + name + ", Happy " + str(age) + end + " birthday!")
time.sleep(5)
Thanks For All Of It Guys,
I have also found another flaw and fixed it, here is my current code.
Thanks.
import time, math
name= input("Enter Your Name: ")
age= int(input("Enter Your Age: "))
end= "th"
if age % 10 == 3:
end = "rd"
elif age % 10 == 2:
end = "nd"
elif age % 10 == 1:
end = "st"
if age < 20 and age > 10:
end = "th"
print ("Your Name Is "+ name + ", You Are " + str(age) + " Years Old.")
print ("Hi " + name + ", Happy " + str(age) + end + " birthday!")
time.sleep(2)
Thanks,
Bilbo

Categories

Resources