0% found this document useful (0 votes)
21 views3 pages

Lab - Week 5 (2021)

İTÜ BIL100E notları

Uploaded by

erdemsimsek234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
21 views3 pages

Lab - Week 5 (2021)

İTÜ BIL100E notları

Uploaded by

erdemsimsek234
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 3
Functions Int lab session, you are going to learn; © Value-returning functions, includin Writing value-returning functions Using value-returning functions ©. Functions returning multiple values © Using library functions and the import statement © Modules, including: © The random and math modules ‘© Grouping your own functions in modules 1) Consider following statements and see the results # Function definition def myprint(s1, print(st) 4 Function call myprint(“Barcelona") myprint("Real Madrid”) # Addition def Fun (x,y): result = x+y return result print(Fun(5,3)) 2) _ Inthe following example, argument is being passed by reference and the reference is being overwritten inside the called function. # pass by reference exanple def ChangeRefer(mylist): mylist = [1,2,3,4] # This assigns a new reference print("First Values : ", mylist) # Now call ChangeRefer function mylist = (1@,20,3@] ChangeRefer( mylist ) print("Secondary Values : ", mylist) # default parameters def printinfo( name, age = 23 ): print("Name: ", name) print("Age: ", age) # Now call printinfo function printinfo( age=19, name="Tasmanian Devil” ) printinfo( nane="Bugs Bunny" ) 3) A. Consider following example about import statement and random number generation. See the results. Seize the difference from random import randint #randint is a function print(randint(@, 100)) import random #random is a module print(random.randint(@,109)) B, Generating random numbers with different ways. See the results. randrange function import random # Select an even number in 160 <= number < 100 print("randrange(100, 1090, 2) : ", random.randrange(100, 1000, 2)) # Select another number in 100 <= number < 1000 print("randrange(102, 102, 3) : ", random.randrange(10@, 1000, 3)) # uniform function print ("Random Float uniform(18, 81) : ", random.uniform(18, 81)) print ("Random Float uniform(19, 38) : ", random.uniform(19, 38)) 4) Consider following statements about using functions for different goals. See the results. # List of directory locations import sys print(sys.path) # how to print pi from math import pi print(pi) # Function that defines an area of a circle import math def area_of_circle(r): arta * math.pi return a print(area_of_circle(3))

You might also like