Ai ML Internship
Ai ML Internship
Ai ML Internship
USN : 2GB18CS010
Year : 4th year
Sub : Internship
Domain : AI/ML
Company : QuantMasters
DAY 1
AI
Machine Learning
Learning
Data Science
Deep Learning
statics
Programing
language
DS
Python or R
Domain
knowledge
DAY 2
PYTHON
IDE(integrated development environment) mean Development Environment for particular program.(like java-
eclipse )
Name.ipynb (.ipynb which stand for
Keywords:
Total 33 keywords (Except 3key words, rest begin with lower case)
They are :True, False & None
Variable name/ identifiers :Begin with alphabets or underscore and contain digits afterwards.
Quotations:
Input : “ “ “ Multi
Line
Comments” “ “
Output : ‘multi\nline\ncoments
Note: Single quotation used for Character and Double quotation used for String in C but not in Python
Because there is no character (char) concept in Python, and there is no char data type.
Note :Every Data Type in Python is Class
#String
If you create string called “hello”. This particular string called hello object of the class
String(str) .
Data Type:
Primitive Data Type
Non Primitive Data Type
Their are mainly 6 Primitive Data types
1)int:
Input : a=5
print(type(a))
output :<class ‘int’>
3)float
Input: b = 5.0
print(type(b))
output :<class ‘float’>
4)Boolean(bool)
Input : bool_value = True
print(type(bool_value))
Output : <class ‘bool’>
5)complex
Input : complex_num =3+5j
print(type(complex_num))
Output : <class ‘complex’>
Input : complex_num =3+5i
print(type(complex_num))
Output : syntax Error : invalid syntax
6)None
Input : element =None
print(type(element))
Output : <class ‘None Type’>
Index:
string = “HELLO WORLD”
0 1 2 3 4 5 6 7 8 9 10
H E L L O W O R L D
- - -9 -8 -7 -6 -5 -4 -3 -2 -1
11 10
1) print(string[0])
output : H
2) print(string[11])
output: Index Error : String index out of Range
3) print [start : end]
print(string[0:4])
output : HELL
{
for (i=o; i<4; i++)
{
Print(string[i])
}
}
4) print [start : stop : step ]
print [0 : 11 : 2 ]
output :HLOWRD
{
for (i=start ; i<stop; i+=step)
{
Print(string[i])
}
}
5) print(string[-1])
output : D
6) print(string[-6 : -1])
output : -WORL
7) print(string[-1 : -6]) {[-1:-6:1]}
output : empty (By default step is +1 , {[-1:-6:1]})
{for [i=-1; i<-6; i=1]}
8) print(string[-1 : -6 : i=-1 ])
output : DLROW
{
for (i=-1 ; i>-6; i=i-1)
{
Print(string[i])
}
}
9) print( : : 1) or print( : : :)
output: HELLO WORLD (0:11:1)
{ Print from left to right (start = 0, stop = length of string)
10) print( : : -1)
output: DLROW OLLEH (-1:-12:-1)
{ Print from right to left reverse of string)
DAY 3
string — Common string operations
https://docs.python.org/3/library/string.html
https://docs.python.org/3/library/stdtypes.html#string
-methods
Example:
a = 5
b = 3
print(a+b) #8
print(a-b) #2
print(a*b) #15
print(a/b) #1.666666666666666667
print(round(a/b,2)) #1.67
print(a%b) # 2
print(a//b) # (Floor Division) 1
print(a**b) # 125
output:
We are
IN IF
Division if a and b is 5.0
End of Program
2) a = 5
b = 10
if(a>b):
print("We are")
print("IN IF")
print("Division if a and b is",a/b)
else: pass
print("End of Program")
Output :
End of Program
Conditional Operators
>
<
>=
<=
==
!=
Input :
a = 10
b = 5
print(a>b)
print(a<b)
print(a==b)
print(a!=b)
print(a>=b)
print(a<=b)
Output :
True
False
False
True
True
False
Logical Operators:
and
or
not
Output:
At least two numbers are equal
Input :
a = 500
b = 500
c = 15
if(a>b):
if(a>c):
print(a,"is greatest")
elif(b>a):
if(b>c):
print(b,"is greatest")
elif(c>a):
if(c>b):
print(c,"is greatest")
else:
print("At least two numbers are equal")
Output :
At least two numbers are equal
Input :
a = 5
b = 4
if(a>b or a>10):
print("IN IF")
Output :
IN IF
Membership operator:
in
not in
If some value is present in some sequence of values
Input :
string = "Hello World"
if "o W" in string:
print("IN IF")
else:
print("IN ELSE")
Output :
IN IF
Input :
string = "Hello World"
if 'o W' not in string:
print("IN IF")
else:
print("IN ELSE")
Output :
IN ELSE
Identity Operator:
is
is not
If both elements point to same memory location, then identity operator returns True
Input :
a = 5
b = 5
print(a is b)
s1 = "Hello"
s2 = "Hello"
print(s1 is s2)
Output :
True
True
Input :
x = 5
y = 5
print(id(x))
print(id(y))
y = 6
print(id(x))
print(id(y))
Output :
94459884255872
94459884255872
94459884255872
94459884255904
Input :
x = 5
print(id(x))
x = 6
print(id(x))
Output :
94459884255872
94459884255904
DAY 4
Strings are immutable within Python
Input :
string = "HELLO"
string[0] = "J"
print(string)
Output :
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-0e56ede7e4e1> in <module>()
1 string = "HELLO"
----> 2 string[0] = "J"
3 print(string)
Input :
#List
li = [1,'2',3,None,True,'Hello']
print(id(li))
li[0] = 5
print(id(li))
print(type(li))
Output :
140035086397024
140035086397024
<class 'list'>
Input :
li1 = [1,2,3]
li2 = [4,5,6]
li2.append(li1) #Adds single element to the end of the list
print(li2)
Output :
[4, 5, 6, [1, 2, 3]]
Input :
li1 = [1,2,3]
li2 = [4,5,6]
li2.extend(li1) #Adds second list to the end of the list
print(li2)
Output :
[4, 5, 6, 1, 2, 3]
Input :
li = [1,2,3,4,6,7,8,9]
li[4] = 5 #replaces 6 with 5
print(li)
Output :
[1, 2, 3, 4, 5, 7, 8, 9]
Input :
li = [1,2,3,4,6,7,8,9]
li.insert(4,5) #insert(index,value)
print(li)
Output :
[1, 2, 3, 4, 5, 6, 7, 8, 9]
Input :
li = [1,2,3,4,6,7,8,9]
print(len(li))
Output :
8
Input :
li = [1,2,1,3]
li.remove(1) #element exists, remove first occurence
print(li)
Output :
[2, 1, 3]
Input :
li = [1,2,1,3]
li.remove(5) #element doesn't occur, gives exception
print(li)
Output :
ValueError Traceback (most recent call last)
<ipython-input-18-33551be326b0> in <module>()
1 li = [1,2,1,3]
----> 2 li.remove(5)
3 print(li)
Input :
li = [1,2,1,3]
li.pop(1) #removes element at index i
print(li)
Output :
[1, 1, 3]
Input :
li = [1,2,1,3]
li.clear()
print(li)
Output :
[]
Input :
li = [1,2,3]
li.append(li) #self referencing list
print(li)
Output :
[1, 2, 3, [...]]
DAY5
Functions:
Purpose:
Reusability
Modularity
Easy to read
NO NO
YES NO
NO YES
YES YES
Function for Even Or Odd
Input:
def evenorodd(var):
if(var%2==0):
print("Even")
else:
print("odd")
evenorodd(5)
Output:
Odd
Input :
#Functions without parameter, no return type
def evenorodd():
if(5%2==0):
print("Even")
else:
print("Odd")
evenorodd()
Output :
odd
Input :
#Functions with parameter, no return type
def evenorodd(var):
if(var%2==0):
print("Even")
else:
print("Odd")
evenorodd(5)
Output :
Input :
#Functions with default parameter, no return type
def evenorodd(var = 20): #20 is the default value if no value is sent.
if(var%2==0):
print("Even")
else:
print("Odd")
evenorodd(5)
Output :
Odd
Input :
#Functions with default parameter, no return type
def evenorodd(var = 20): #20 is the default value if no value is sent.
if(var%2==0):
print("Even")
else:
print("Odd")
evenorodd()
Output :
Even
Input :
#Functions with default parameter, no return type
def evenorodd(var): #20 is the default value if no value is sent.
if(var%2==0):
return "even"
else:
return "odd"
string = evenorodd(20)
print(string)
Output :
even
Input :
def fun(string):
return string[0:5],string[6:]
var1,var2 = fun("Hello World")
print(var1,var2,sep='\n')
Output :
Hello
World
SORT FUNCTION
Input :
#sort
#lists of only homogeneous elements can be sorted.
li = [1,2,3,"hello"]
li.sort()
print(li)
Output :
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-36-280787342afb> in <module>()
2 #lists of only homogeneous elements can be sorted.
3 li = [1,2,3,"hello"]
----> 4 li.sort()
5 print(li)
Input :
#sort
#lists of only homogeneous elements can be sorted.
li = [1,2,3,2.5]
li.sort()
print(li)
Output :
[1, 2, 2.5, 3]
1)Given a list of strings (Consider car names), sort the strings in the descending order of number of vowels in
them. Use inbuilt sort function of list ONLY!
Tesla Model S Toyota GT86 2013 Ford Fiesta ST (and 2018) BMW i8 Alfa Romeo Giulia QV 2017 Honda Civic
Type R Ferrari 458 Speciale McLaren P1 Ferrari LaFerrari Porsche 918.
Implement a function to find out how to reverse a number Implement a function to find out whether a number is
prime or not Implement a function to find nth fibonacci number
Input :
list_of_strings = ["Tesla Model S","Toyota GT86","2013 Ford Fiesta ST (and 2018)","BMW i8", "Alfa Romeo Giulia QV","2017
Honda Civic Type R","Ferrari 458 Speciale","McLaren P1","Ferrari LaFerrari","Porsche 918"]
list_of_strings.sort(reverse = False)
print(list_of_strings)
Output :
['2013 Ford Fiesta ST (and 2018)', '2017 Honda Civic Type R', 'Alfa Romeo Giulia QV', 'BMW i8', 'Ferrari 458 Speciale', 'Ferrari
LaFerrari', 'McLaren P1', 'Porsche 918', 'Tesla Model S', 'Toyota GT86']
Input :
list_of_strings = ["Tesla Model S","Toyota GT86","2013 Ford Fiesta ST (and 2018)","BMW i8","Alfa Romeo Giulia QV","2017
Honda Civic Type R","Ferrari 458 Speciale","McLaren P1","Ferrari LaFerrari","Porsche 918"]
list_of_strings.sort(reverse = True)
print(list_of_strings)
Output :
['Toyota GT86', 'Tesla Model S', 'Porsche 918', 'McLaren P1', 'Ferrari LaFerrari', 'Ferrari 458 Speciale', 'BMW i8', 'Alfa Romeo
Giulia QV', '2017 Honda Civic Type R', '2013 Ford Fiesta ST (and 2018)'
Input :
def countVowels(string):
count = 0
string = string.upper()
vowel_list = ['A','E','I','O','U']
for character in string:
if character in vowel_list:
count+=1
return count
list_of_strings = ["Tesla Model S","Toyota GT86","2013 Ford Fiesta ST (and 2018)","BMW i8","Alfa Romeo Giulia QV","2017
Honda Civic Type R","Ferrari 458 Speciale","McLaren P1","Ferrari LaFerrari","Porsche 918"]
list_of_strings.sort(key = countVowels,reverse = True)
print(list_of_strings)
Output :
['Alfa Romeo Giulia QV', 'Ferrari 458 Speciale', 'Ferrari LaFerrari', '2013 Ford Fiesta ST (and 2018)', '2017 Honda Civic Type R',
'Tesla Model S', 'Toyota GT86', 'McLaren P1', 'Porsche 918', 'BMW i8']
Input :
li = [1,2,3,4,5,6]
li2 = li #li2 is a reference to li
li.pop()
print(li2)
Output :
[1, 2, 3, 4, 5]
Input :
li = [1,2,3,4,5,6]
li2 = li.copy() #li2 is a copy of li in a separate memory location
li.pop()
print(li2)
Output :
[1, 2, 3, 4, 5, 6]
Tuple
A Constant set of elements Immutable (No functions such as insert / pop)
Input
t = (1,2,3,4,5,6)
print(type(t))
output
<class 'tuple'>
Input
t = (1,2,3,4,5,6)
for element in t:
print(element)
output
1
2
3
4
5
6
Input
t = (1,2,3,4,5,6)
li = list(t) #Converting tuple to a list
li.pop()
print(li)
output
[1, 2, 3, 4, 5]
SET
Collection of unique elements
Set is mutable
Elements of different datatypes can be stored
Union, Intersection, Difference, all of these functions can be performed between two elements of datatype set
Input
s1 = {1,2,3,4,5,"Hello"}
print(s1)
print(type(s1))
output
{1, 2, 3, 4, 5, 'Hello'}
<class 'set'>
Input
s1 = {}
print(type(s1))
ouput
<class 'dict'>
Input
s1 = set()
print(type(s1))
print(s1)
ouput
<class 'set'>
set()
input
s1 = set()
s1.add(1)
s1.add(2)
s1.add(3)
print(s1)
output
{1, 2, 3}
Input
s1 = set()
s1.add(1)
s1.add(2)
s1.add(3)
li = [4,5,6]
s1.add(li)
print(s1)
output
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-5-c3b6ab77ffec> in <module>()
4 s1.add(3)
5 li = [4,5,6]
----> 6 s1.add(li)
7 print(s1)
s1.add(1)
s1.add(2)
s1.add(3)
li = [3,4,5,6]
s1.update(li)
print(s1)
Input
s1 = {1,2,3,4,5}
s1.discard(3)
print(s1)
s1.discard(3) #Doesn't give error if element is not present within set
print(s1)
Input
s1 = {1,4,5,3,2} #hashed data
s1.discard(3)
print(s1)
s1.discard(3) #Doesn't give error if element is not present within set
print(s1)
Input
s1 = {1,4,5,3,2} #hashed data
s1.remove(3)
print(s1)
s1.remove(3) #gives error if element is not present within set
print(s1)
input
string = "HELLO"
for element in string:
print(element)
output
H
E
L
L
O
input
list_of_strings = ["Tesla Model S","Toyota GT86","2013 Ford Fiesta ST (and 2018)","BMW i8",
"Alfa Romeo Giulia QV","2017 Honda Civic Type R","Ferrari 458 Speciale",
"McLaren P1","Ferrari LaFerrari","Porsche 918"]
for element in list_of_strings:
output
Tesla Model S
Toyota GT86
2013 Ford Fiesta ST (and 2018)
BMW i8
Alfa Romeo Giulia QV
2017 Honda Civic Type R
Ferrari 458 Speciale
McLaren P1
Ferrari LaFerrari
Porsche 918
input
list_of_strings = ["Tesla Model S","Toyota GT86"]
for string in list_of_strings:
for character in string:
print(character)
output
T
e
s
l
a
M
o
d
e
l
S
T
o
y
o
t
a
G
T
8
6
DAY 6
ASSIGNMENT QUESTION
Every valid email consists of a local name and a domain name, separated by the '@' sign. Besides lowercase
letters, the email may contain one or more '.' or '+'.
For example, in "alice@leetcode.com", "alice" is the local name, and "leetcode.com" is the domain name.
If you add periods '.' between some characters in the local name part of an email address, mail sent there will be
forwarded to the same address without dots in the local name. Note that this rule does not apply to domain names.
For example, "alice.z@leetcode.com" and "alicez@leetcode.com" forward to the same email address.
If you add a plus '+' in the local name, everything after the first plus sign will be ignored. This allows certain
emails to be filtered. Note that this rule does not apply to domain names.
For example, "m.y+name@email.com" will be forwarded to "my@email.com".
Input
def findUniqueEmails(input_str):
uniqueEmails = set()
for email in input_str:
local,domain = email.split('@')
local = local.split('+')[0]
local = local.replace('.','')
local = local+'@'+domain
uniqueEmails.add(local)
print(len(uniqueEmails))
input_str = ["test.email+alex@leetcode.com","test.e.mail+bob.cathy@leetcode.com","testemail+david@lee.tcode.com"]
findUniqueEmails(input_str)
output
Input
s1 = {1,2,3,4,5,6}
s2 = {4,5,6,7,8,9}
print(s1.union(s2))
output
{1, 2, 3, 4, 5, 6, 7, 8, 9}
Input
s1 = {1,2,3,4,5,6}
s2 = {4,5,6,7,8,9}
print(s1.intersection(s2))
output
{4, 5, 6}
Input
s1 = {1,2,3,4,5,6}
s2 = {4,5,6,7,8,9}
print(s1.isdisjoint(s2))
output
False
Input
s1 = {4,5,6}
s2 = {4,5,6,7,8,9}
print(s1.issubset(s2))
print(s2.issuperset(s1))
ouput
True
True
Input
s1 = {11,15,16,64,12,5476,8645}
print(s1)
output
{64, 5476, 8645, 11, 12, 15, 16}
https://mathworld.wolfram.com/HashFunction.html
Dictionary
https://docs.python.org/3/library/2to3.html?highlight=dict#2to3fixer-dict
hashabe set of key-value pairs Written within {} Unordered
input
https://mathworld.wolfram.com/HashFunction.html
output
{'Good': 'Positive', 'Evil': 'Negative', 'Great': 'Positive'}
Input
d = {"Good":"Positive","Evil":"Negative","Great":"Positive"}
print(d[0])
output
KeyError Traceback (most recent call last)
<ipython-input-20-590d56a94b27> in <module>()
1 d = {"Good":"Positive","Evil":"Negative","Great":"Positive"}
----> 2 print(d[0])
KeyError: 0
Input
d = {"Good":"Positive","Evil":"Negative","Great":"Positive"}
print(d["Good"])
output
Positive
Input
d = {"Good":"Positive","Evil":"Negative","Great":"Positive"}
print(d.get("Good"))
output
Positive
Input
d = {"Good":"Positive","Evil":"Negative","Great":"Positive"}
print(d["Goods"])
ouput
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-27-198c2e2bdae2> in <module>()
1 d = {"Good":"Positive","Evil":"Negative","Great":"Positive"}
----> 2 print(d["Goods"])
KeyError: 'Goods'
Input
d = {"Good":"Positive","Evil":"Negative","Great":"Positive"}
print(d.get("Goods"))
ouput
None
Input
d = {1:"Positive","Evil":"Negative","Great":"Positive"}
print(d.get(1))
output
Positive
Input
d = {"Good":"Positive","Evil":"Negative","Great":"Positive","Good":"Negative"}
print(d)
output
{'Good': 'Negative', 'Evil': 'Negative', 'Great': 'Positive'}
Input
d = {
"location": {
"name": "London",
"region": "City of London, Greater London",
"country": "United Kingdom",
"lat": 51.52,
"lon": -0.11,
"tz_id": "Europe/London",
"localtime_epoch": 1572750389,
"localtime": "2019-11-03 3:06"
},
"forecast": {
"forecastday": [
{
"date": "2018-01-31",
"date_epoch": 1517356800,
"day": {
"maxtemp_c": 9.7,
"maxtemp_f": 49.5,
"mintemp_c": 4.5,
"mintemp_f": 40,
"avgtemp_c": 7.8,
"avgtemp_f": 46,
"maxwind_mph": 17.7,
"maxwind_kph": 28.4,
"totalprecip_mm": 0.22,
"totalprecip_in": 0.01,
"avgvis_km": 9,
"avgvis_miles": 5,
"avghumidity": 69,
"condition": {
"text": "Sunny",
"icon": "//cdn.weatherapi.com/weather/64x64/day/113.png",
"code": 1000
},
"uv": 0
},
"astro": {
"sunrise": "07:41 AM",
"sunset": "04:48 PM",
"moonrise": "04:55 PM",
"moonset": "07:33 AM",
"moon_phase": "Waxing Gibbous",
"moon_illumination": "97"
},
"hour": [
{
"time_epoch": 1517356800,
"time": "2018-01-31 00:00",
"temp_c": 9.6,
"temp_f": 49.3,
"is_day": 0,
"condition": {
"text": "Overcast",
"icon": "//cdn.weatherapi.com/weather/64x64/night/122.png",
"code": 1009
},
"wind_mph": 14.3,
"wind_kph": 23,
"wind_degree": 231,
"wind_dir": "SW",
"pressure_mb": 1013,
"pressure_in": 30.4,
"precip_mm": 0,
"precip_in": 0,
"humidity": 90,
"cloud": 100,
"feelslike_c": 6.6,
"feelslike_f": 43.9,
"windchill_c": 6.6,
"windchill_f": 43.9,
"heatindex_c": 9.6,
"heatindex_f": 49.3,
"dewpoint_c": 8,
"dewpoint_f": 46.4,
"will_it_rain": 0,
"chance_of_rain": "0",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
},
{
"time_epoch": 1517360400,
"time": "2018-01-31 01:00",
"temp_c": 9.7,
"temp_f": 49.4,
"is_day": 0,
"condition": {
"text": "Overcast",
"icon": "//cdn.weatherapi.com/weather/64x64/night/122.png",
"code": 1009
},
"wind_mph": 15.2,
"wind_kph": 24.5,
"wind_degree": 234,
"wind_dir": "SW",
"pressure_mb": 1012,
"pressure_in": 30.4,
"precip_mm": 0,
"precip_in": 0,
"humidity": 86,
"cloud": 100,
"feelslike_c": 6.5,
"feelslike_f": 43.7,
"windchill_c": 6.5,
"windchill_f": 43.7,
"heatindex_c": 9.6,
"heatindex_f": 49.3,
"dewpoint_c": 7.4,
"dewpoint_f": 45.2,
"will_it_rain": 0,
"chance_of_rain": "3",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
},
{
"time_epoch": 1517364000,
"time": "2018-01-31 02:00",
"temp_c": 9.7,
"temp_f": 49.4,
"is_day": 0,
"condition": {
"text": "Overcast",
"icon": "//cdn.weatherapi.com/weather/64x64/night/122.png",
"code": 1009
},
"wind_mph": 16.1,
"wind_kph": 25.9,
"wind_degree": 237,
"wind_dir": "WSW",
"pressure_mb": 1011,
"pressure_in": 30.3,
"precip_mm": 0,
"precip_in": 0,
"humidity": 82,
"cloud": 100,
"feelslike_c": 6.4,
"feelslike_f": 43.6,
"windchill_c": 6.4,
"windchill_f": 43.6,
"heatindex_c": 9.7,
"heatindex_f": 49.4,
"dewpoint_c": 6.7,
"dewpoint_f": 44.1,
"will_it_rain": 0,
"chance_of_rain": "3",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
},
{
"time_epoch": 1517367600,
"time": "2018-01-31 03:00",
"temp_c": 9.7,
"temp_f": 49.5,
"is_day": 0,
"condition": {
"text": "Overcast",
"icon": "//cdn.weatherapi.com/weather/64x64/night/122.png",
"code": 1009
},
"wind_mph": 17,
"wind_kph": 27.4,
"wind_degree": 240,
"wind_dir": "WSW",
"pressure_mb": 1010,
"pressure_in": 30.3,
"precip_mm": 0,
"precip_in": 0,
"humidity": 78,
"cloud": 100,
"feelslike_c": 6.4,
"feelslike_f": 43.5,
"windchill_c": 6.4,
"windchill_f": 43.5,
"heatindex_c": 9.7,
"heatindex_f": 49.5,
"dewpoint_c": 6,
"dewpoint_f": 42.9,
"will_it_rain": 0,
"chance_of_rain": "0",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
},
{
"time_epoch": 1517371200,
"time": "2018-01-31 04:00",
"temp_c": 9.3,
"temp_f": 48.8,
"is_day": 0,
"condition": {
"text": "Overcast",
"icon": "//cdn.weatherapi.com/weather/64x64/night/122.png",
"code": 1009
},
"wind_mph": 15.7,
"wind_kph": 25.3,
"wind_degree": 239,
"wind_dir": "WSW",
"pressure_mb": 1009,
"pressure_in": 30.3,
"precip_mm": 0,
"precip_in": 0,
"humidity": 78,
"cloud": 100,
"feelslike_c": 6.1,
"feelslike_f": 42.9,
"windchill_c": 6.1,
"windchill_f": 42.9,
"heatindex_c": 9.3,
"heatindex_f": 48.8,
"dewpoint_c": 5.8,
"dewpoint_f": 42.4,
"will_it_rain": 0,
"chance_of_rain": "3",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
},
{
"time_epoch": 1517374800,
"time": "2018-01-31 05:00",
"temp_c": 8.9,
"temp_f": 48.1,
"is_day": 0,
"condition": {
"text": "Overcast",
"icon": "//cdn.weatherapi.com/weather/64x64/night/122.png",
"code": 1009
},
"wind_mph": 14.5,
"wind_kph": 23.3,
"wind_degree": 239,
"wind_dir": "WSW",
"pressure_mb": 1008,
"pressure_in": 30.2,
"precip_mm": 0,
"precip_in": 0,
"humidity": 79,
"cloud": 100,
"feelslike_c": 5.8,
"feelslike_f": 42.4,
"windchill_c": 5.8,
"windchill_f": 42.4,
"heatindex_c": 9,
"heatindex_f": 48.1,
"dewpoint_c": 5.5,
"dewpoint_f": 41.8,
"will_it_rain": 0,
"chance_of_rain": "3",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
},
{
"time_epoch": 1517378400,
"time": "2018-01-31 06:00",
"temp_c": 8.6,
"temp_f": 47.4,
"is_day": 0,
"condition": {
"text": "Overcast",
"icon": "//cdn.weatherapi.com/weather/64x64/night/122.png",
"code": 1009
},
"wind_mph": 13.2,
"wind_kph": 21.2,
"wind_degree": 238,
"wind_dir": "WSW",
"pressure_mb": 1007,
"pressure_in": 30.2,
"precip_mm": 0,
"precip_in": 0,
"humidity": 79,
"cloud": 100,
"feelslike_c": 5.5,
"feelslike_f": 41.9,
"windchill_c": 5.5,
"windchill_f": 41.9,
"heatindex_c": 8.6,
"heatindex_f": 47.5,
"dewpoint_c": 5.2,
"dewpoint_f": 41.3,
"will_it_rain": 0,
"chance_of_rain": "0",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
},
{
"time_epoch": 1517382000,
"time": "2018-01-31 07:00",
"temp_c": 8.6,
"temp_f": 47.5,
"is_day": 0,
"condition": {
"text": "Overcast",
"icon": "//cdn.weatherapi.com/weather/64x64/night/122.png",
"code": 1009
},
"wind_mph": 14.6,
"wind_kph": 23.5,
"wind_degree": 243,
"wind_dir": "WSW",
"pressure_mb": 1006,
"pressure_in": 30.2,
"precip_mm": 0,
"precip_in": 0,
"humidity": 78,
"cloud": 100,
"feelslike_c": 5.4,
"feelslike_f": 41.7,
"windchill_c": 5.4,
"windchill_f": 41.7,
"heatindex_c": 8.7,
"heatindex_f": 47.6,
"dewpoint_c": 5.1,
"dewpoint_f": 41.2,
"will_it_rain": 0,
"chance_of_rain": "3",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 7.3,
"vis_miles": 4
},
{
"time_epoch": 1517385600,
"time": "2018-01-31 08:00",
"temp_c": 8.7,
"temp_f": 47.7,
"is_day": 1,
"condition": {
"text": "Light drizzle",
"icon": "//cdn.weatherapi.com/weather/64x64/day/266.png",
"code": 1153
},
"wind_mph": 16,
"wind_kph": 25.8,
"wind_degree": 248,
"wind_dir": "WSW",
"pressure_mb": 1006,
"pressure_in": 30.2,
"precip_mm": 0.07,
"precip_in": 0,
"humidity": 77,
"cloud": 100,
"feelslike_c": 5.3,
"feelslike_f": 41.5,
"windchill_c": 5.3,
"windchill_f": 41.5,
"heatindex_c": 8.7,
"heatindex_f": 47.7,
"dewpoint_c": 5,
"dewpoint_f": 41,
"will_it_rain": 0,
"chance_of_rain": "51",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 4.7,
"vis_miles": 2
},
{
"time_epoch": 1517396400,
"time": "2018-01-31 11:00",
"temp_c": 8.5,
"temp_f": 47.3,
"is_day": 1,
"condition": {
"text": "Cloudy",
"icon": "//cdn.weatherapi.com/weather/64x64/day/119.png",
"code": 1006
},
"wind_mph": 15.7,
"wind_kph": 25.2,
"wind_degree": 263,
"wind_dir": "W",
"pressure_mb": 1004,
"pressure_in": 30.1,
"precip_mm": 0,
"precip_in": 0,
"humidity": 64,
"cloud": 90,
"feelslike_c": 5,
"feelslike_f": 41.1,
"windchill_c": 5,
"windchill_f": 41.1,
"heatindex_c": 8.5,
"heatindex_f": 47.4,
"dewpoint_c": 2.1,
"dewpoint_f": 35.9,
"will_it_rain": 0,
"chance_of_rain": "2",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 7.3,
"vis_miles": 4
},
{
"time_epoch": 1517400000,
"time": "2018-01-31 12:00",
"temp_c": 8.4,
"temp_f": 47.1,
"is_day": 1,
"condition": {
"text": "Cloudy",
"icon": "//cdn.weatherapi.com/weather/64x64/day/119.png",
"code": 1006
},
"wind_mph": 14.8,
"wind_kph": 23.8,
"wind_degree": 268,
"wind_dir": "W",
"pressure_mb": 1004,
"pressure_in": 30.1,
"precip_mm": 0,
"precip_in": 0,
"humidity": 58,
"cloud": 85,
"feelslike_c": 5,
"feelslike_f": 41,
"windchill_c": 5,
"windchill_f": 41,
"heatindex_c": 8.4,
"heatindex_f": 47.1,
"dewpoint_c": 0.7,
"dewpoint_f": 33.3,
"will_it_rain": 0,
"chance_of_rain": "0",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
},
{
"time_epoch": 1517403600,
"time": "2018-01-31 13:00",
"temp_c": 8,
"temp_f": 46.4,
"is_day": 1,
"condition": {
"text": "Cloudy",
"icon": "//cdn.weatherapi.com/weather/64x64/day/119.png",
"code": 1006
},
"wind_mph": 15.7,
"wind_kph": 25.3,
"wind_degree": 270,
"wind_dir": "W",
"pressure_mb": 1003,
"pressure_in": 30.1,
"precip_mm": 0,
"precip_in": 0,
"humidity": 56,
"cloud": 61,
"feelslike_c": 4.4,
"feelslike_f": 39.9,
"windchill_c": 4.4,
"windchill_f": 39.9,
"heatindex_c": 8,
"heatindex_f": 46.5,
"dewpoint_c": -0.3,
"dewpoint_f": 31.6,
"will_it_rain": 0,
"chance_of_rain": "2",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
},
{
"time_epoch": 1517407200,
"time": "2018-01-31 14:00",
"temp_c": 7.7,
"temp_f": 45.8,
"is_day": 1,
"condition": {
"text": "Sunny",
"icon": "//cdn.weatherapi.com/weather/64x64/day/113.png",
"code": 1000
},
"wind_mph": 16.7,
"wind_kph": 26.9,
"wind_degree": 273,
"wind_dir": "W",
"pressure_mb": 1003,
"pressure_in": 30.1,
"precip_mm": 0,
"precip_in": 0,
"humidity": 53,
"cloud": 36,
"feelslike_c": 3.8,
"feelslike_f": 38.8,
"windchill_c": 3.8,
"windchill_f": 38.8,
"heatindex_c": 7.7,
"heatindex_f": 45.8,
"dewpoint_c": -1.2,
"dewpoint_f": 29.8,
"will_it_rain": 0,
"chance_of_rain": "0",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
},
{
"time_epoch": 1517410800,
"time": "2018-01-31 15:00",
"temp_c": 7.3,
"temp_f": 45.2,
"is_day": 1,
"condition": {
"text": "Sunny",
"icon": "//cdn.weatherapi.com/weather/64x64/day/113.png",
"code": 1000
},
"wind_mph": 17.7,
"wind_kph": 28.4,
"wind_degree": 276,
"wind_dir": "W",
"pressure_mb": 1003,
"pressure_in": 30.1,
"precip_mm": 0,
"precip_in": 0,
"humidity": 51,
"cloud": 12,
"feelslike_c": 3.2,
"feelslike_f": 37.7,
"windchill_c": 3.2,
"windchill_f": 37.7,
"heatindex_c": 7.3,
"heatindex_f": 45.1,
"dewpoint_c": -2.2,
"dewpoint_f": 28,
"will_it_rain": 0,
"chance_of_rain": "0",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
},
{
"time_epoch": 1517414400,
"time": "2018-01-31 16:00",
"temp_c": 6.6,
"temp_f": 43.9,
"is_day": 1,
"condition": {
"text": "Sunny",
"icon": "//cdn.weatherapi.com/weather/64x64/day/113.png",
"code": 1000
},
"wind_mph": 15.9,
"wind_kph": 25.6,
"wind_degree": 269,
"wind_dir": "W",
"pressure_mb": 1002,
"pressure_in": 30.1,
"precip_mm": 0,
"precip_in": 0,
"humidity": 53,
"cloud": 9,
"feelslike_c": 2.6,
"feelslike_f": 36.7,
"windchill_c": 2.6,
"windchill_f": 36.7,
"heatindex_c": 6.6,
"heatindex_f": 43.9,
"dewpoint_c": -2.2,
"dewpoint_f": 28,
"will_it_rain": 0,
"chance_of_rain": "0",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
},
{
"time_epoch": 1517418000,
"time": "2018-01-31 17:00",
"temp_c": 5.9,
"temp_f": 42.6,
"is_day": 0,
"condition": {
"text": "Clear",
"icon": "//cdn.weatherapi.com/weather/64x64/night/113.png",
"code": 1000
},
"wind_mph": 14.1,
"wind_kph": 22.7,
"wind_degree": 263,
"wind_dir": "W",
"pressure_mb": 1002,
"pressure_in": 30.1,
"precip_mm": 0,
"precip_in": 0,
"humidity": 56,
"cloud": 6,
"feelslike_c": 2,
"feelslike_f": 35.7,
"windchill_c": 2,
"windchill_f": 35.7,
"heatindex_c": 6,
"heatindex_f": 42.7,
"dewpoint_c": -2.2,
"dewpoint_f": 28,
"will_it_rain": 0,
"chance_of_rain": "0",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
},
{
"time_epoch": 1517432400,
"time": "2018-01-31 21:00",
"temp_c": 4.5,
"temp_f": 40,
"is_day": 0,
"condition": {
"text": "Clear",
"icon": "//cdn.weatherapi.com/weather/64x64/night/113.png",
"code": 1000
},
"wind_mph": 14.1,
"wind_kph": 22.7,
"wind_degree": 257,
"wind_dir": "WSW",
"pressure_mb": 1001,
"pressure_in": 30,
"precip_mm": 0,
"precip_in": 0,
"humidity": 62,
"cloud": 11,
"feelslike_c": 0.1,
"feelslike_f": 32.2,
"windchill_c": 0.1,
"windchill_f": 32.2,
"heatindex_c": 4.5,
"heatindex_f": 40.1,
"dewpoint_c": -2.1,
"dewpoint_f": 28.3,
"will_it_rain": 0,
"chance_of_rain": "0",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
},
{
"time_epoch": 1517436000,
"time": "2018-01-31 22:00",
"temp_c": 4.2,
"temp_f": 39.5,
"is_day": 0,
"condition": {
"text": "Clear",
"icon": "//cdn.weatherapi.com/weather/64x64/night/113.png",
"code": 1000
},
"wind_mph": 13.3,
"wind_kph": 21.4,
"wind_degree": 251,
"wind_dir": "WSW",
"pressure_mb": 1001,
"pressure_in": 30,
"precip_mm": 0,
"precip_in": 0,
"humidity": 64,
"cloud": 15,
"feelslike_c": -0.1,
"feelslike_f": 31.8,
"windchill_c": -0.1,
"windchill_f": 31.8,
"heatindex_c": 4.2,
"heatindex_f": 39.6,
"dewpoint_c": -2,
"dewpoint_f": 28.5,
"will_it_rain": 0,
"chance_of_rain": "0",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
},
{
"time_epoch": 1517439600,
"time": "2018-01-31 23:00",
"temp_c": 3.8,
"temp_f": 38.9,
"is_day": 0,
"condition": {
"text": "Clear",
"icon": "//cdn.weatherapi.com/weather/64x64/night/113.png",
"code": 1000
},
"wind_mph": 12.5,
"wind_kph": 20,
"wind_degree": 246,
"wind_dir": "WSW",
"pressure_mb": 1000,
"pressure_in": 30,
"precip_mm": 0,
"precip_in": 0,
"humidity": 66,
"cloud": 19,
"feelslike_c": -0.3,
"feelslike_f": 31.4,
"windchill_c": -0.3,
"windchill_f": 31.4,
"heatindex_c": 3.9,
"heatindex_f": 39,
"dewpoint_c": -1.9,
"dewpoint_f": 28.7,
"will_it_rain": 0,
"chance_of_rain": "0",
"will_it_snow": 0,
"chance_of_snow": "0",
"vis_km": 10,
"vis_miles": 6
}
]
}
]
}
}
print(d["forecast"]['forecastday'][0]['day']['maxtemp_c'])
output
9.7
input
#For loop with numbers
for i in range(10): #range(start = 0,stop,step = 1)
print(i)
output
0
1
2
3
4
5
6
7
8
9
Input
#For loop with numbers
for i in range(1,11): #range(start = 0,stop,step = 1)
print(i)
ouput
1
2
3
4
5
6
7
8
9
10
Input
#For loop with numbers
for i in range(5,101,5): #range(start = 0,stop,step = 1)
print(i,end="\t")
output
5 10 15 20 25 30
Input
#For loop with numbers
for i in range(10,0,-1): #range(start = 0,stop,step = 1)
print(i,end="\t")
ouput
10 9 8 7 6 5
https://openweathermap.org/api
DAY 7
INPUT DATA
Input
a = input("Enter the value of a\n") #By default reads strings
b = input("Enter the value of b\n")
c = a + b
print(c)
output
Enter the value of a
10
Enter ther value of b
20
1020
Input
a = int(input("Enter the value of a\n")) #By default reads strings
b = int(input("Enter the value of b\n"))
c = a + b
print(c)
output
a = int(input("Enter the value of a\n")) #By default reads strings
b = int(input("Enter the value of b\n"))
c = a + b
print(c)
input
#Array
n = int(input("Enter number of elements > "))
array_list = []
for i in range(1,n+1):
string = "Enter the element number "+str(i)+": "
array_list.append(int(input(string)))
print(array_list)
output
Enter number of elements > 5
Enter the element number 1: 10
Enter the element number 2: 20
Enter the element number 3: 30
Enter the element number 4: 40
Enter the element number 5: 50
[10, 20, 30, 40, 50]
Input
#Read 2D Array
two_dim = []
rows = int(input("Enter number of rows > "))
cols = int(input("Enter number of columns > "))
for i in range(0,rows):
temp = []
for j in range(0,cols):
string = "Enter the element number ["+str(i)+"]["+str(j)+"]: "
temp.append(int(input(string)))
two_dim.append(temp)
print(two_dim)
output
Enter number of rows > 3
Enter number of columns > 3
Enter the element number [0][0]: 1
Enter the element number [0][1]: 2
Enter the element number [0][2]: 3
Enter the element number [1][0]: 4
Enter the element number [1][1]: 5
Enter the element number [1][2]: 6
Enter the element number [2][0]: 7
Enter the element number [2][1]: 8
Enter the element number [2][2]: 9
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
#List Comprehension - shortcut for creating a list using for loops
Input
fruits = ["kiwi","apple","mango","strawberry","cherry","watermelon"]
fruits_lengthy = []
for f in fruits:
if(len(f)>5):
fruits_lengthy.append(f)
print(fruits_lengthy)
output
['strawberry', 'cherry', 'watermelon']
Input
#List Comprehension - shortcut for creating a list using for loops
fruits = ["kiwi","apple","mango","strawberry","cherry","watermelon"]
fruits_lengthy = [f for f in fruits if(len(f)>5)]
#[if_statement for_loop if_condition_within_for_loop]
print(fruits_lengthy)
output
['strawberry', 'cherry', 'watermelon']
Input
range_loop = [i for i in range(1,11)]
print(range_loop)
output
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Input
fruits = ["kiwi","apple","mango","strawberry","cherry","watermelon"]
#If a fruit ends with o, add es. otherwise add s.
#[if_statement if_condition else else_statement for_loop]
fruits_plural = [f+"es" if f.endswith('o') else f+"s" for f in fruits]
print(fruits_plural)
'''
Same as:
for f in fruits:
if f.endswith('o'):
fruits_plural.append(f+"es")
else:
fruits_plural.append(f+"s")
'''
Output
['kiwis', 'apples', 'mangoes', 'strawberrys', 'cherrys', 'watermelons']
Input
fruits = ["kiwi","apple","mango","strawberry","cherry","watermelon"]
#[if_statement if_condition else statement if_condition else else_statement for_loop]
fruits_plural = [f+"es" if f.endswith('o') else f[0:-1]+"ies" if f.endswith('y') else f
+"s" for f in fruits]
'''
for f in fruits:
if f.endswith('o'):
fruits_plural.append(f+"es")
elif f.endswith('y'):
fruits_plural.append(f[0:-1]+"ies")
else:
fruits_plural.append(f+"s")
'''
print(fruits_plural)
output
['kiwis', 'apples', 'mangoes', 'strawberries', 'cherries', 'watermelons']
Input
#Lambda FUnctions - Anonymous Function
fun = lambda a : a**2
print(fun(5))
Output
25
Input
#Lambda FUnctions - Anonymous Function
fun = lambda a,b : a*b
print(fun(5,10))
output
50
Marks given 0 - 100 0 to 34, fail 35 - 59, B Grade 60 - 89, A Grade 90 - 100, Outstanding
Input: 4 [10,55,89,95] Output: ["Fail","B Grade","A Grade","Outstanding"]
Only using List Comprehension
Marks given 0 - 100
0 to 34, fail
35 - 59, B Grade
60 - 89, A Grade
90 - 100, Outstanding
Input:
4
[10,55,89,95]
Output: ["Fail","B Grade","A Grade","Outstanding"]
DAY 8
def fun():
print(a+b)
a = 5 #global by default
b = 10
fun()
OUTPUT
15
INPUT
del a,b
a = 5 #global by default
b = 10
def fun():
print(a+b)
fun()
OUTPUT
INPUT
del a,b
def fun():
print(a+b)
fun()
a = 5 #global by default
b = 10
OUTPUT
INPUT
del a,b
def fun():
a = 5 #global by default
b = 10
fun()
print(a+b)
INPUT
a = 10
def fun():
global a
a = a*2
print(a)
fun()
print(a)
OUTPUT
20
20
INPUT
a = 10
def fun():
a = 10
a = a*2
print(a)
fun()
print(a)
OUTPUT
10
20
FILE OPERATIONS
INPUT
file_handle = open("/content/Text_File.txt")
result = file_handle.readlines()
file_handle.close()
print(result)
OUTPUT
INPUT
file_handle = open("/content/Text_File.txt")
result = file_handle.readline()
file_handle.close()
print(result)
OUTPUT
INPUT
file_handle = open("/content/Write_File.txt","w")
file_handle.write("Hello World")
file_handle.close()
file_handle = open("/content/Write_File.txt")
print(file_handle.readlines())
file_handle.close()
EXCEPTION HANDLING
Exceptions are runtime errors which are unchecked by the compiler / interpreter.
INPUT
file_handle = open("/content/NEW_FILE.txt")
print(file_handle.readlines())
file_handle.close()
try:
file_handle = open("/content/Write_File.txt")
print(file_handle.readlines())
file_handle.close()
except:
print("Oops! File doesn't exist. Please try again")
try:
file_handle = open("/content/Write_Files.txt")
print(file_handle.readlines())
file_handle.close()
except:
print("Oops! File doesn't exist. Please try again")
https://docs.python.org/3/library/exceptions.html
import sys
try:
a = int(input())
b = int(input())
print(a/b)
except:
print("Do not divide by 0")
print(sys.exc_info()[0])
print("End of the Program")
import sys
try:
a = int(input())
b = int(input())
print(a/b)
except ValueError:
print("Enter a proper integer number")
print(sys.exc_info()[0])
except ZeroDivisionError:
print("Do not divide by 0")
print(sys.exc_info()[0])
print("End of the Program")
import sys
while(True):
try:
a = int(input("Enter value of a > ")) #ValueError
b = int(input("Enter value of b > ")) #ValueError
print(a/b) #ZeroDivisionError
break
except ValueError:
print("Enter a proper integer number")
print(sys.ex0c_info()[0])
except ZeroDivisionError:
print("Do not divide by 0")
print(sys.exc_info()[0])
print("End of the Program")
import sys
while(True):
try:
file_handle = open("/content/Write_Files.txt")
a = int(input("Enter value of a > ")) #ValueError
b = int(input("Enter value of b > ")) #ValueError
print(a/b) #ZeroDivisionError
break
except ValueError:
print("Enter a proper integer number")
print(sys.ex0c_info()[0])
except ZeroDivisionError:
print("Do not divide by 0")
print(sys.exc_info()[0])
finally: #executes all times (Whether exception occurs or not)
file_handle.close()
print("End of the Program")
boss = EnemyCharacters()
henchman = EnemyCharacters()
boss.health = 5000
boss.ammo = 5000
henchman.health = 10
boss.printDetails();
henchman.printDetails();
output
Health: 5000
Ammo: 5000
Health: 10
Ammo: 50
DAY9
Input
class EnemyCharacters:
health = 100 #attributes
ammo = 50
def hide(self): #methods
print("Do hiding")
def shoot(self):
print("Do shooting")
def reload(self):
print("Do reload")
def printDetails(self):
print("Health:",self.health)
print("Ammo:",self.ammo)
class FlyingEnemy(EnemyCharacters):
def fly(self):
print("Do Flying")
class SwimmingEnemy(EnemyCharacters):
def swim(self):
print("Do swimming")
f = FlyingEnemy()
s = SwimmingEnemy()
f.fly()
f.printDetails()
s.swim()
s.printDetails()
output
Do Flying
Health: 100
Ammo: 50
Do swimming
Health: 100
Ammo: 50
Input
#__init__ -> Constructor (Executes the moment an object is created)\
class EnemyCharacters:
health = 100 #attributes
ammo = 50
def hide(self): #methods
print("Do hiding")
def shoot(self):
print("Do shooting")
def reload(self):
print("Do reload")
def printDetails(self):
print("Health:",self.health)
print("Ammo:",self.ammo)
class FlyingEnemy(EnemyCharacters):
def __init__(self):
print("Assign Object of Flying Weapon")
def __init__(self,a):
print("Assign Object of Flying Weapon")
def fly(self):
print("Do Flying")
class SwimmingEnemy(EnemyCharacters):
def __init__(self):
print("Assign Object of Swimming Weapon")
def swim(self):
print("Do swimming")
f = FlyingEnemy()
s = SwimmingEnemy()
output
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-8c70f98ae35c> in <module>()
28 print("Do swimming")
29
---> 30 f = FlyingEnemy()
31 f = FlyingEnemy(10)
32 s = SwimmingEnemy()
TypeError: __init__() missing 1 required position
Input
class A:
def funA(self):
print("IN FUN A")
class B:
def funB(self):
print("IN FUN B")
class C(A,B):
pass
c_object = C()
c_object.funA()
c_object.funB()
output
IN FUN A
IN FUN B
Input
class A:
def fun(self):
print("IN FUN A")
class B:
def fun(self):
print("IN FUN B")
class C(A,B):
pass
c_object = C()
c_object.fun()
c_object.fun()
output
IN FUN B
IN FUN B
https://colab.research.google.com/drive/1aOiBwyByWk0lyqmP0VpKwzkGyUBY8p21