You are on page 1of 4

MODULE 5 LOOPS and Functions

Please implement Python coding for all the problems.

1. A) list1=[1,5.5,(10+20j),’data science’].. Print default functions and parameters exists in


list1.
B) How do we create a sequence of numbers in Python.
C) Read the input from keyboard and print a sequence of numbers up to that number

2. Create 2 lists.. one list contains 10 numbers (list1=[0,1,2,3....9]) and other


list contains words of those 10 numbers (list2=['zero','one','two',.... ,'nine']).
Create a dictionary such that list2 are keys and list 1 are values..

3. Consider a list1 [3,4,5,6,7,8]. Create a new list2 such that Add 10 to the even number
and multiply with 5 if it is odd number in the list1..

4. Write a simple user defined function that greets a person in such a way that :

i) It should accept both name of person and message you want to deliver.

ii) If no message is provided, it should greet a default message ‘How are you’

Ex: Hello ---xxxx---, How are you - default message.

Ex: Hello ---xxxx---, --xx your message xx---

################ Assingments MODULE 5 LOOPS and Functions ################

#1.A) list1=[1,5.5,(10+20j),’data science’].. Print default functions and parameters exists in list1.

# B) How do we create a sequence of numbers in Python.

# C) Read the input from keyboard and print a sequence of numbers up to that number

list1=[1,5.5,(10+20j),'data science']
print(list1)

Numbers = list(range(10))

num = int(input("enter your num: "))

for num in range(num):

print(num)

###### 2.Create 2 lists..

list1=[0,1,2,3,4,5,6,7,8,9]

list2=['zero','one','two','three','four','five','six','seven','eight','nine']

#Create a dictionary such that list2 are keys and list1 are values..

dict1 = {}

dict1['zero'] = 0

dict1['one'] = 1

dict1['two'] = 2

dict1['three'] = 3

dict1['four'] = 4

dict1['five'] = 5

dict1['six'] = 6
dict1['seven'] = 7

dict1['eight'] = 8

dict1['nine'] = 9

dict1['ten'] = 10

dict1

#3.Consider a list1 [3,4,5,6,7,8]. Create a new list2 such that Add 10 to the even number and
multiply with 5 if it is odd number in the list1..

list1 = [3,4,5,6,7,8]

list2 = []

for num in list1:

if num%2 == 0:

list2.append(num + 10)

else:

list2.append(num*5)

list2

### Write a simple user defined function that greets a person in such a way that :

# i) It should accept both name of person and message you want to deliver.

# ii) If no message is provided, it should greet a default message ‘How are you’
def greet(name= 'How are you'):

gr = 'Hello' + name

return gr

a=greet('Kamlesh')

a=greet()

def greet(name, msg = 'How are you?'):

print('Hello', name + "" + msg)

greet('Kamlesh')

You might also like