Professional Documents
Culture Documents
Learning Udemy
Learning Udemy
a = 10 #Integer
b = 'Hello' #String
c = [33, 33.5, 'Temperature'] #List
d = {'isb':32, 'rwp':36, 'gujarkhan':37} #Dictionary
e = (33, 33.5, 'Temperature') #Tuple
def mean(marks):
if type(marks) == dict:
my_mean = sum(marks.values()) / len (marks)
else:
my_mean= sum (marks) / len (marks)
return my_mean
OR
def mean(marks):
if isinstance(marks, dict):
my_mean = sum(marks.values()) / len (marks)
else:
my_mean= sum (marks) / len (marks)
return my_mean
User Inputs
def func(marks):
if marks >= 34:
return 'pass'
else:
return 'fail'
Loops:
Lists
colors = [11, 34.1, 98.2, 43, 45.1, 54, 54]
for col in colors:
if isinstance(col,int):
print(col)
Dictionary
colors = {'red' : 11, 'yellow': 34.1, 'black' : 98.2}
for col in colors.items():
print(col)
for col in colors.keys():
print(col)
for col in colors.values():
print(col)
password = ''
while password != 'dose':
password = input('Enter your password : ')
print (' You are in ')
OR
while True:
password = input('Enter your password : ')
if password == 'dose':
break
else:
continue
print('your are in ')
First Program
def operation(temp):
interogatives = ('How','What','Why','When')
temp2 = temp.capitalize()
if temp2.startswith(interogatives):
return f'{temp2}?'
else:
return f'{temp2}.'
results = []
while True:
temp = input('Say : ')
if temp == '\end':
break
else:
results.append(operation(temp))
List comprehension
def greater(user_list):
return [temp/2 for temp in user_list if isintance]