4th July .Ipynb - Colaboratory
4th July .Ipynb - Colaboratory
ipynb - Colaboratory
String printing
print("enter")
enter
o=10
print("enter"+str(o))
enter10
x,y,z = 9.2,8,10
import numpy
Combining 2 strings
Adding 2 integers
Simple calculator
https://colab.research.google.com/drive/1S1QtoFIz9SOjc-i1LFPtPqDlcz8_S7ud#scrollTo=t2uO1HTChWcb&printMode=true 1/4
04/07/2023, 16:44 4th july .ipynb - Colaboratory
print("Select operation.")
print("1.Add")
print("2.Subtract")
print("3.Multiply")
print("4.Divide")
while True:
# take input from the user
choice = input("Enter choice(1/2/3/4): ")
if choice == '1':
print(num1, "+", num2, "=", add(num1, num2))
Select operation.
1.Add
2.Subtract
3.Multiply
4.Divide
Enter choice(1/2/3/4): 1
Enter first number: 12
Enter second number: 2
12.0 + 2.0 = 14.0
Let's do next calculation? (yes/no): yes
Enter choice(1/2/3/4): 2
Enter first number: 23
Enter second number: 2
23.0 - 2.0 = 21.0
Let's do next calculation? (yes/no): no
# Lists
l = []
# Dictionary
d = {}
https://colab.research.google.com/drive/1S1QtoFIz9SOjc-i1LFPtPqDlcz8_S7ud#scrollTo=t2uO1HTChWcb&printMode=true 2/4
04/07/2023, 16:44 4th july .ipynb - Colaboratory
d[10] = "Ten"
print("Dictionary", d)
Tuple (5,)
set
# Set
s = set()
print(type(d))
<class 'dict'>
Tuple ()
The first item has index 0.
-1 refers to the last item, -2 refers to the second last item etc.
damini
devu
# Tuple
t = tuple(l)
Tuple (5,)
Dictionary {}
key value pair {"damini" : "good" , "samosa" :"bad" }
https://colab.research.google.com/drive/1S1QtoFIz9SOjc-i1LFPtPqDlcz8_S7ud#scrollTo=t2uO1HTChWcb&printMode=true 3/4
04/07/2023, 16:44 4th july .ipynb - Colaboratory
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict)
print(thisdict["brand"])
Ford
print(thisdict["brand"])
Ford
print(len(thisdict))
print("Original tuple:", z)
print("Multiplied tuple:", result)
C l b id d t C l t t h
check 0s completed at 4:38 PM
https://colab.research.google.com/drive/1S1QtoFIz9SOjc-i1LFPtPqDlcz8_S7ud#scrollTo=t2uO1HTChWcb&printMode=true 4/4