76. Example of return
def allowed_dating_age(my_age):
girls_age = my_age/2 + 7
return girls_age
Age_limit = allowed_dating_age(34)
print("You can date girls", Age_limit, "or older")
allowed_dating_age(34)
77. Example of set
groceries = {'cereal','milk','starcrunch','beer','duct tape','lotion','beer'}
print(groceries)
if 'milk' in groceries:
print("You already have milk hoss!")
else:
print("Oh yes you need milk!")
78. Example of variable scope
#a = 1514
def test1():
a = 1514
print(a)
def test2():
print(a)
test1()
test2()
79. Example of dictionary
myDict = {'manish': 'bidsar','abc': 'efg'}
print(myDict)
print(myDict['manish'])
print(myDict["manish"])
varstr = "this is manish " \
"from Karnataka " \
"India."
80. Example for prime number
for num in range(2,20):
if num%2 == 0:
print ('num is not prime')
#break
else:
print ('num is prime number')
x = range(2,9)
print(x)
No comments:
Post a Comment