This file is used to test the packages and modules we build.
from istec.p4.exercises import exercise1,greetingsfrom istec.p4.exercises import lists,datatypes,dictionariesfrom istec.p4.exercises import tuples,setsfrom istec.p4.exercises import decisions,repetitions,functions# These are just the first exercisesprint("Working with Python Packages")exercise1.hello()greetings.good_morning()greetings.good_afternoon()# Exercises with Stringsprint("Working with Strings")mystring ="Sport Lisboa e Benfica"print(datatypes.stringpart(mystring,12))print(datatypes.myupper(mystring))print(datatypes.mylower(mystring))print(datatypes.invertsizing(datatypes.myupper(mystring)))print(datatypes.invertsizing(datatypes.mylower(mystring)))# Exercises with Listsprint("Working with Lists")mystring ="a caminho do Marquês"print(lists.myfirstnames(mystring.split()))print(lists.mylist(mystring))print("Dá-me o ",lists.mylistnum(38))last2champs ="Porto Porto"# This is a string later converted to a list of words#last2champs = ["Porto",Porto"] # This is the same data as above but already as a listprint(lists.myaddremove(last2champs.split(), "Benfica", "Porto")) # Function split() converts a sentence/string with words to a list of words# Exercises with Dictionariesprint("Working with Dictionaries")teams = ["Benfica","Porto","Braga","Sporting","Arouca"]points = [80,73,71,64,48]print(dictionaries.mydictionary(teams,points))championscup = {'Benfica': 80, 'Porto': 73, 'Braga': 71}europecup = ["Sporting","Arouca"]points = [64,48]print(dictionaries.mydictionary2(championscup,europecup,points))# Exercises with Tuplesprint("Working with Tuples")cars = ["Bmw","Audi","Volvo"]speeds = [250,230,220]print(tuples.mytuple(cars,speeds))cars.append("Audi")speeds.append(240)print(tuples.mytuple2(cars,speeds))print(tuples.mytuplecount(tuples.mytuple2(cars,speeds)))# Exercises with Setsprint("Working with Sets")commercial = ["Bmw","Audi","Volvo","Mercedes","Ferrari"]fone = ["Bmw","McLaren","Mercedes","Ferrari","Williams"]print(sets.myset(commercial,fone))print(sets.myset2(sets.myset(commercial,fone)))print(sets.myset3(sets.myset(commercial,fone)))print(sets.myset4(sets.myset(commercial,fone)))rally = {"Audi","Mercedes","Renault"}print(sets.myset5((sets.myset(commercial,fone),rally)))# Working with Decisionsprint("Working with Decisions")print(decisions.mydecision(commercial,fone))print(decisions.mydecision2(commercial,fone))# Working with Repetitionsprint("Working with Repetitions")print(repetitions.myrepetition(commercial,fone))hpower = (520,622,640, 675, 618)print(repetitions.myrepetition2(commercial,hpower))cyl=[10,40,0,50,0]print(repetitions.myrepetition3(commercial,hpower,cyl))a = ["A","A",23,24,25]b = ["A","B","A","C","D","A"]print(tuples.mytuplecount(tuples.mytuple2(a , b))["A"])# Working with Functions# Working with User-Defined Functionsprint("Working with User-Defined Functions")BTC=[400,600,440,500,550,600,750,600,1200,1110,1000,950]print(functions.myudffunction1(BTC,600))# Working with Lambda Functionsprint("Working with Lambda Functions")print(functions.mylambdafunction1(BTC))print(functions.mylambdafunction2(BTC))# Working with Recursive Functionsprint("Working with Recursive Functions")for n inrange(1,10):print("Factorial of",n,"is:",myrecursivefunction1(n))n=12print("Countdown from",n)myrecursivefunction2(n)list=[1,2,3,4,5,6,7]print("Multiplication of",list)print(myrecursivefunction3(list))print("Multiplication of odd positions in ",list)print(myrecursivefunction4(list))# Working with Object Oriented Programming# Working with Classesprint("Working with Classes")from istec.p4.exercises.oop import Studentdisciplinas = {"Prog4":["26/07",0,["Book1,pdf","Book2.pdf"]],"DS":["25/08",0,["Book3,pdf","Book4.pdf"]],"Networking":["26/09",0,["Book5,pdf","Book6.pdf"]]}student1 = Student("Joao", 35, disciplinas)print(student1.name)print(student1.age)print(student1.classes)print(student1)# Working with Methodsprint("Working with Methods")student1.removedisciplines(["Networking"])print(student1.classes)newdisciplines = {"Engenharia de Software":["2/07",0,["Book52,pdf","Book62.pdf"]],"Multimedia":["2/07",0,["Book50,pdf","Book60.pdf"]]}student1.adddisciplines(newdisciplines)print(student1.classes)newgrades = {"Engenharia de Software":15, "Multimedia":16}student1.addgrades(newgrades)print(student1.classes)print(student1.alldisciplines())print(student1.allgrades())disciplinas = {"Cloud Computing":["26/07",0,["Book1,pdf","Book2.pdf"]]}student2 = Student("Luis",25, disciplinas)print(student2.name)print(student2.age)print(student2.classes)print(student1)print(student1.classes)print(student2)print(student2.classes)
Your folder tree should now be similar to this when looked from inside folder project1