0% found this document useful (0 votes)
15 views

4th Jan - Python - Ipynb - Colaboratory

Uploaded by

Mansi Salar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

4th Jan - Python - Ipynb - Colaboratory

Uploaded by

Mansi Salar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1/4/24, 9:00 PM 4th Jan - Python.

ipynb - Colaboratory

Conditional Statement

a = int(input("Enter a number:"))
print(a)
print(type(a))

account_circle Enter a number:6


6
<class 'int'>

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

Loops - For | While

## 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 loop

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

### Break and continue statement

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

1. Function without argument or attributes


2. Function with argument or attributes
3. Function with default argument or attributes
4. Function with return statement

print()

len()

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-26-adf3103c7c3e> in <cell line: 1>()
----> 1 len()

TypeError: len() takes exactly one argument (0 given)

SEARCH STACK OVERFLOW

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

You might also like