# Hello World program in Python print ("My Dear Mother"); print () print ("Sometimes I wish that I were back at home,") print ("In the loving arms that held me strong.") print ("To reassure my safety, my peace, my soul;) print ("To let me know that everything was okay, that you were in control.") But reality has set in, my course is now set; Guided by your love, making no move that I would regret. You hath raised me, raised a man, a man of values indeed. Your instructions on life I live by and have learned to take heed. Obedience is therefore greater than any sacrifice I can make, And I'd rather die horrifically, than your heart at any time I break. Love you, yes indeed, far greater than any other. A lady of profound beauty and wisdom, but above all MY MOTHER.
# Hello World program in Python print (" The Dog"); print () print ("There is once a dog named Douglas"); print ("He loves to play with his owner Jao.") print ("He also loves to eat anything except chocolate because it is toxic to him.") print ("He also likes to chase anything he wants and also likes to lay down all day.") print ("One day he noticed that his owners left the house.\nHe also noticed that no one is around.") print ("He felt so lonely and he waited all day long for his owners to come back.") print ("At last his long wait was over because he saw his owners coming back.") print ("He is very happy that he wiggled his tail endlessly") print ("And they played around all day in the backyard.") print ("He was so happy to play with his owner and he very loves them so much.") print () print("THE END")
""" Herhangi bir sayının karesi, o sayının bir altındaki sayı ile bir üstündeki sayının çarpımının bir fazlasına eşittir. Yukarıdaki bilgiye dayanarak 1'den 100'e kadar olan sayıların karesini hesaplayan ve yanında da math kütüphanesinin pow fonksiyonunu kullanarak sağlamasını yapan programı yazınız. Ekran Görüntüsü --------------------------------------------------- 1 sayısının karesi = 1 --> 1 (sağlama) 2 sayısının karesi = 4 --> 4 (sağlama) 3 sayısının karesi = 9 --> 9 (sağlama) 4 sayısının karesi = 16 --> 16 (sağlama) 5 sayısının karesi = 25 --> 25 (sağlama) .. ................ . ... ... ... ......... 98 sayısının karesi = 9604 --> 9604 (sağlama) 99 sayısının karesi = 9801 --> 9801 (sağlama) 100 sayısının karesi = 10000 --> 10000 (sağlama) """ import math for a in range(1, 101, 1): kare = (a - 1) * (a + 1) + 1 print (a, "sayısının karesi =", kare, " --> ", int(math.pow(a, 2)) , " (sağlama)");
import math def distance(p1, p2): d = math.sqrt( ((p1[0]-p2[0])**2) + ((p1[1]-p2[1])**2) ) return d def triclosestdistance(p1, p2, p3): d1 = math.sqrt( ((p1[0]-p2[0])**2) + ((p1[1]-p2[1])**2) ) d2 = math.sqrt( ((p1[0]-p3[0])**2) + ((p1[1]-p3[1])**2) ) d3 = math.sqrt( ((p3[0]-p2[0])**2) + ((p3[1]-p2[1])**2) ) if (d1 >= d2) and (d1 >= d3): largest = d1 elif (d2 >= d1) and (d2 >= d3): largest = d2 else: largest = d3 return largest def trishortestpath(p1, p2, p3): d1 = math.sqrt( ((p1[0]-p2[0])**2) + ((p1[1]-p2[1])**2) ) #1 to 2 d2 = math.sqrt( ((p1[0]-p3[0])**2) + ((p1[1]-p3[1])**2) ) #1 to 3 d3 = math.sqrt( ((p3[0]-p2[0])**2) + ((p3[1]-p2[1])**2) ) #2 to 3 path1 = d1 + d3 # 1,2,3 path2 = d2 + d3 # 1,3,2 path3 = d1 + d2 # 2,1,3 path4 = d3 + d2 # 2,3,1 path5 = d2 + d1 # 3,1,2 path6 = d3 + d1 # 3,2,1 if (path1 <= path2) and (path1 <= path3) and (path1 <= path4) and (path1 <= path5) and (path1 <= path6): largest = "1 to 2 to 3 is (one of) the shortest: " + str(path1) elif (path2 <= path1) and (path2 <= path3) and (path2 <= path4) and (path2 <= path5) and (path2 <= path6): largest = "1 to 3 to 2 is (one of) the shortest: " + str(path2) elif (path3 <= path1) and (path3 <= path2) and (path3 <= path4) and (path3 <= path5) and (path3 <= path6): largest = "2 to 1 to 3 is (one of) the shortest: " + str(path3) elif (path4 <= path1) and (path4 <= path2) and (path4 <= path3) and (path4 <= path5) and (path4 <= path6): largest = "2 to 3 to 1 is (one of) the shortest: " + str(path4) elif (path5 <= path1) and (path5 <= path2) and (path5 <= path3) and (path5 <= path4) and (path5 <= path6): largest = "3 to 1 to 2 is (one of) the shortest: " + str(path5) else: largest = "3 to 2 to 1 is (one of) the shortest: " + str(path6) return largest x = [324, 100] y = [1341, 31] z = [-13243410,3.5] print (trishortestpath(x,y,z))
# Funciones 2 # Parameters of list type def fncMayor(prmList): print(" ", prmList) for x in range len(prmlist): print(x) def fncCreaLista(): print(); print(" Parameters of list type:") lista = [5, 9, 1, 7, 3] fncMayor(lista) fncCreaLista() # return of a list # parameters with default value # call to the function with named arguments # variable amount of parameters
# zadatak od korisnika prihvaća podatke za 5 studenata i zatim ih ispisuje # sortirane po abecedi (usporedba n-torki) i sortirane po prosjeku # (potrebno je najprije izmijeniti redoslijed elemenata u n-torci) # napomena: prije pokretanja programa unijeti podatke o studentima u STDIN # u zasebne redove # unos podataka za 5 studenata studenti = [] for i in range(5): prezime_ime = str(input('')) ID = input() prosjek = input() student = (prezime_ime[:-1], int(ID[:-1]), float(prosjek[:-1])) studenti.append(student) print (studenti) print('----------') # sortiranje studenata po abecedi i ispis studenti.sort() print('Studenti sortirani po abecedi:') for s in studenti: print(s) print('----------') # kreiranje liste n-torki sa izmijenjenim redoslijedom studenti_po_prosjeku = [] for s in studenti: studenti_po_prosjeku.append((s[2], s[0], s[1])) print(studenti_po_prosjeku) print('----------') # sortiranje po prosjeku (silazno) i ispis studenti_po_prosjeku.sort(reverse = True) print('Studenti sortirani po prosjeku:') for s in studenti_po_prosjeku: print(s) print('----------') # nije moguće izbrisati n-torku koja je element liste iterativnim prolaskom for s in studenti_po_prosjeku: del(s) print(studenti_po_prosjeku) print('----------') # brisanje pojedinačne n-torke moj_tuple = (1, 2, 3) print(moj_tuple) del(moj_tuple) # print(moj_tuple)
class Person: def __init__(self,name,age,height): self.name=name self.age=age self.height=height def eat(self): print('Eating') def walk(self): print('Walking') def getname(self): return self.name p1=Person('Mansuri',18,4) print(p1.eat())
# i/p: a4b3c2 #o/p : aaaabbbcc #convert string to list #get the odd indexes as it contains no., convert it to no., multiply it with even s="a4b3c2" l1=[] i=0 for x in s: l1.append(s[i]) i=i+1 print(l1) i=1 l2=[] for x in range(0,len(s)): if(i+2)<len(s)+2: #to check last index, i=5, our +2 logic may throw index out of range l2.append(int(s[i])) i=i+2 print(l2) i=0 j=0 res="" for x in s: if(i+2)<len(s)+2: res=res+l1[i]*l2[j] i=i+2 j=j+1 print(res)
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more