import module as mp print(mp.mylist[0]) add = mp.sum(5, 7) print(add) p1 = mp.Person("Nirajan", "Bekoju") p1.printname() print(dir(mp)) a = [] n = int(input("Enter no of elements : ")) for x in range(0, n): a.append(int(input("Enter elemet" + str(x + 1) + ": "))) print("Element in a[] are: ") print(a) b = [] for x in a: if x not in b: b.append(x) print("Element in b[] : ", b) print(len(b))
# class Person: # def __init__(self,name,age,nama_lawan,age_lawan): # self.name = name # self.age = age # self.nama_lawan = nama_lawan # # self.age_lawan = age_lawan # def sapa(self): # print("Halo, namaku "+self.name) # print("Nama kamu siapa?") # def salamkenal(self): # print("Salam kenal "+self.nama_lawan) # print("Senang bertemu denganmu, sampai jumpa kembali") import module p1 = module.Person("Nafi", 22, "Dodit") p1.sapa() p1.salamkenal() # p1 = Person("Nafi",22) # p2 = Person("Dodit",24) # print(p1.name) # print(p1.age) # print(p2.name) # print(p2.age)
import module as m p1 = m.Person("Person 1", 20) p1.talk("Hello!") p1.ask("what is your name?")
#!/usr/bin/python3 import module from random import randint, sample print(f"Sum 4 + 5 = {module.sum(4,5)}") print(f"Name is {module.name}") person = module.Person.parse_person('Jane') defPerson = module.Person() print(f'\v The default person is {defPerson.get_name()}') print(f' The new person is {person.get_name()}') words = [ 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten' ] count = randint(1, 10) print('random number {}\n and selected word {}'.format(count, words[count])) print(f"sample word = {sample(words, count)}")