4th Jan - Python - Ipynb - Colaboratory
4th Jan - Python - Ipynb - Colaboratory
ipynb - Colaboratory
Conditional Statement
a = int(input("Enter a number:"))
print(a)
print(type(a))
a = int(input("Enter a number:"))
if a>=0:
print("Positive Number")
else:
print("Negative Number")
Enter a number:-4
Negative Number
a = int(input("Enter a number:"))
if a>0:
print("Positive Number")
elif a==0:
print("It's a zero")
else:
print("Negative Number")
Enter a number:0
It's a zero
a = int(input("Enter a number:"))
if a>0:
print("Positive Number")
elif a==0:
print("It's a zero")
elif a<0:
print("Negative Number")
Enter a number:-8
Negative Number
## While Loop
i = 0
while i<10:
print("The value of i is "+str(i))
i = i+1
"a"+str(1)
'a1'
while True:
print("Infinite Loop")
i = 0
while i<10:
print("The value of i is",i)
i = i+1
for i in range(10):
print("The value of i is "+str(i))
The value of i is 0
The value of i is 1
The value of i is 2
The value of i is 3
The value of i is 4
The value of i is 5
The value of i is 6
https://colab.research.google.com/drive/1u65e9DAcYRKVBHTZQko3hbkbruxIqFPj#scrollTo=4yYj9MOOFi-v&printMode=true 1/3
1/4/24, 9:00 PM 4th Jan - Python.ipynb - Colaboratory
The value of i is 7
The value of i is 8
The value of i is 9
for i in range(20):
print("The value of i is "+str(i))
The value of i is 0
The value of i is 1
The value of i is 2
The value of i is 3
The value of i is 4
The value of i is 5
The value of i is 6
The value of i is 7
The value of i is 8
The value of i is 9
The value of i is 10
The value of i is 11
The value of i is 12
The value of i is 13
The value of i is 14
The value of i is 15
The value of i is 16
The value of i is 17
The value of i is 18
The value of i is 19
for i in range(10,20):
print("The value of i is "+str(i))
The value of i is 10
The value of i is 11
The value of i is 12
The value of i is 13
The value of i is 14
The value of i is 15
The value of i is 16
The value of i is 17
The value of i is 18
The value of i is 19
for i in range(10,30,3):
print("The value of i is "+str(i))
The value of i is 10
The value of i is 13
The value of i is 16
The value of i is 19
The value of i is 22
The value of i is 25
The value of i is 28
nos = []
while True:
a = int(input("Enter a number:"))
if a == 0:
break
nos.append(a)
print(nos)
Enter a number:3
Enter a number:4
Enter a number:2
Enter a number:5
Enter a number:3
Enter a number:0
[3, 4, 2, 5, 3]
nos = []
while True:
a = int(input("Enter a number:"))
if a == 0:
break
if a in nos:
continue
nos.append(a)
print(nos)
https://colab.research.google.com/drive/1u65e9DAcYRKVBHTZQko3hbkbruxIqFPj#scrollTo=4yYj9MOOFi-v&printMode=true 2/3
1/4/24, 9:00 PM 4th Jan - Python.ipynb - Colaboratory
Enter a number:1
Enter a number:2
Enter a number:2
Enter a number:3
Enter a number:3
Enter a number:0
[1, 2, 3]
Functions
print()
len()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-26-adf3103c7c3e> in <cell line: 1>()
----> 1 len()
a = print("Umang")
Umang
print(a)
None
a = len("Umang")
print(a)
https://colab.research.google.com/drive/1u65e9DAcYRKVBHTZQko3hbkbruxIqFPj#scrollTo=4yYj9MOOFi-v&printMode=true 3/3