0% found this document useful (0 votes)
23 views4 pages

4th July .Ipynb - Colaboratory

The document discusses various Python programming concepts like string manipulation, arithmetic operations, conditional statements, functions, lists, tuples, dictionaries and sets. It includes examples like a basic calculator program using functions, manipulating list and dictionary data types, slicing tuples and multiplying tuple elements.

Uploaded by

miniature test
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)
23 views4 pages

4th July .Ipynb - Colaboratory

The document discusses various Python programming concepts like string manipulation, arithmetic operations, conditional statements, functions, lists, tuples, dictionaries and sets. It includes examples like a basic calculator program using functions, manipulating list and dictionary data types, slicing tuples and multiplying tuple elements.

Uploaded by

miniature test
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/ 4

04/07/2023, 16:44 4th july .

ipynb - Colaboratory

4th July 2023 FDP ❄


Damini Nijgal

String printing

print("enter")

enter

Number assigniand printing

o=10

Concatenation of String and Number

print("enter"+str(o))

enter10

q=input("enter your name")

Multiple assigning of number and values

x,y,z = 9.2,8,10

import numpy

Combining 2 strings

w = input ("enter the your first name")


e = input ("enter the your last name")
r= w+e
print(r)

enter the your first name1


enter the your last name2
12

Adding 2 integers

m = int( input ("enter the your first value "))


n = int(input ("enter the your second value"))
v= m+n
print(v)

enter the your first value 1


enter the your second value4
5

Simple calculator

1) elif 2) operations 3) Assigning variables

def add(xa, ya):


return xa + ya

# This function subtracts two numbers


def subtract(xa, ya):
return xa - ya

# This function multiplies two numbers


def multiply(xa, ya):
return xa * ya

# This function divides two numbers


def divide(xa, ya):
return xa / ya

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): ")

# check if choice is one of the four options


if choice in ('1', '2', '3', '4'):
try:
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
except ValueError:
print("Invalid input. Please enter a number.")
continue

if choice == '1':
print(num1, "+", num2, "=", add(num1, num2))

elif choice == '2':


print(num1, "-", num2, "=", subtract(num1, num2))

elif choice == '3':


print(num1, "*", num2, "=", multiply(num1, num2))

elif choice == '4':


print(num1, "/", num2, "=", divide(num1, num2))

# check if user wants another calculation


# break the while loop if answer is no
next_calculation = input("Let's do next calculation? (yes/no): ")
if next_calculation == "no":
break
else:
print("Invalid Input")

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

List [] , Tuple () , Dict {}

# Lists
l = []

# Adding Element into list


l.append(5)
l.append(10)
print("Adding 5 and 10 in list", l)

# Popping Elements from list


l.pop()
print("Popped one element from list", l)
print()

# Dictionary
d = {}

# Adding the key value pair


d[5] = "Five"

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)

# Removing key-value pair


del d[10]
print("Dictionary", d)

Adding 5 and 10 in list [5, 10]


Popped one element from list [5]

Tuple (5,)

Dictionary {5: 'Five', 10: 'Ten'}


Dictionary {5: 'Five'}

set

# Set
s = set()

# Adding element into set


s.add(5)
s.add(10)
print("Adding 5 and 10 in set", s)

# Removing element from set


s.remove(5)
print("Removing 5 from set", s)
print()

Adding 5 and 10 in set {10, 5}


Removing 5 from set {10}

Under the type of D

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.

thistuple = ("Aashiek", "damini", "devu")


print(thistuple[1])

damini

thistuple = ("aravind", "damini", "devu")


print(thistuple[-1])

devu

# Tuple
t = tuple(l)

# Tuples are immutable


print("Tuple", t)
print()

Tuple (5,)

thistuple = ("aravind", "damini", "devu","anand","vikas","nikhal")


print(thistuple[2:5])

('devu', 'anand', 'vikas')

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)

{'brand': 'Ford', 'model': 'Mustang', 'year': 1964}

print(thisdict["brand"])

Ford

print(thisdict["brand"])

Ford

print(len(thisdict))

write a py Program multiple each element of z = (2,3,6,57,800)

z = (2, 3, 6, 57, 800)


multiplier = 2
result = tuple(element * multiplier for element in z)

print("Original tuple:", z)
print("Multiplied tuple:", result)

Original tuple: (2, 3, 6, 57, 800)


Multiplied tuple: (4, 6, 12, 114, 1600)

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

You might also like