Python (Jupyter Notebook) 1) If you haven’t yet, pack up your code…
Question Answered step-by-step Python (Jupyter Notebook) 1) If you haven’t yet, pack up your code… Python (Jupyter Notebook)1) If you haven’t yet, pack up your code in coursework 2 into functions. User a main() function to call the other functions, e.g. age() function to calculate age, wt_zodiac() to obtain western zodiac, etcCOURSEWORK 2 CODE:from datetime import datetimeimport pandas as pdimport numpy as npplay =TrueUID_list =[] # this will hold the user IDsname_list =[] # this will hold the namesDoB_list = [] # to hold DOBage_list =[]zodiac_list =[]count=0while play:try: #read user IDreader = input(“Enter your 2 digit user ID. For examply 17: “)user_id = int(reader)if len(str(user_id)) != 2: #ensure that user ID is two digits ONLYif str(user_id) == “end”: #condition to stop the gameplay=Falseelse:print(“Your ID is supposed to be two digits. Please provide a correct ID.”)continuename = input(“Enter your name: “)dob = input(“Enter your date of birth in the form dd/mm/yy, for example 30/03/1879: ” )UID_list.append(user_id)name_list.append(name)DoB_list.append(dob )#use current year and the year of birth to calculate the age of the gamerage_list.append(datetime.now().year – pd.to_datetime(dob).year)month = pd.to_datetime(dob).month #extract month and day to use for zodiac signday = pd.to_datetime(dob).day#determine Zodiac signif (month == 3 and day>=21):zodiac_list.append(“Aries”)elif month==4 and day <=19 :zodiac_list.append("Aries") elif (month ==4 and day>=20):zodiac_list.append(“Taurus”)elif month==5 and day <=20 :zodiac_list.append("Tauru")elif (month ==5 and day>=21):zodiac_list.append(“Gemini”)elif month==6 and day <=20 :zodiac_list.append("Gemini")elif (month ==6 and day>=21):zodiac_list.append(“Cancer”)elif month==7 and day <= 22:zodiac_list.append("Cancer")elif (month ==7 and day>=23):zodiac_list.append(“Leo”)elif month==8 and day <= 22:zodiac_list.append("Leo")elif (month ==8 and day>=23):zodiac_list.append(“Virgo”)elif month==9 and day <= 22:zodiac_list.append("Virgo")elif (month ==9 and day>=23):zodiac_list.append(“Libra”)elif month==10 and day <= 22:zodiac_list.append("Libra")elif (month ==10 and day>=23):zodiac_list.append(“Scorpio”)elif month==11 and day <=21 :zodiac_list.append("Scorpio")elif (month ==11 and day>=22):zodiac_list.append(“Sagittarius”)elif month==12 and day <=21 :zodiac_list.append("Sagittarius")elif (month ==12 and day>=22):zodiac_list.append(“Capricorn”)elif month==1 and day <= 19:zodiac_list.append("Capricorn")elif (month ==1 and day>=20):zodiac_list.append(“Aquarius”)elif month==2 and day <= 18:zodiac_list.append("Aquarius")elif (month ==2 and day>=19):zodiac_list.append(“Pisces”)elif month==3 and day <= 20:zodiac_list.append("Pisces")except :print("You did not provide an integer as ID. Please follow the rule of the game.")if reader == "end":play=Falsecontinuecount+=1if count ==3:play=Falsedf = pd.DataFrame(np.column_stack([UID_list,name_list,DoB_list,age_list,zodiac_list]),columns=["UID","Name","DoB","Age","Weatern Zodiac"])df = df.sort_values("UID")# sort the data by the UIDdf.head()#prints out 10 records of the data8. According to each user's birth year, add another cn_zodiac() function to calculate the animal associated with that year's Chinese zodiac.12. Save the data into a new local file named "Zodiac.txt".13. (advanced) Extend your program with one more function that makes your program better- you can do whatever you want. Remember to use clear comments to make your program self-explanatory. Computer Science Engineering & Technology Python Programming COMPUTERS 101 Share QuestionEmailCopy link Comments (0)


