Skip to content

Latest commit

 

History

History
95 lines (91 loc) · 1.69 KB

46. Unit 4 - Lesson 7.md

File metadata and controls

95 lines (91 loc) · 1.69 KB

Introduction to Tuples

Q1. 3,4,6
Q2.

mytuple = ("i", "love", "python")
print("Given Tuple:",mytuple)
list=list(mytuple)
print("After Converting Tuple into List:",list)
list[1]="practice"

print("List after changing element:",list)
print("After Converting List into Tuple:",tuple(list))

#Write the missing code here

Q3. Need Solution

Basic Tuples Operations

Q1. 3,4
Q2.

d=input("data: ")
l=d.split(",")
print("list:",l)
t=tuple(l)
print("tuple:",t)
i=int(input("index: "))
if i<len(l):
	print("element:",l[i])
else:
	print("enter valid index")

Q3.

mytuple = ("this", 10.0, "is", "float", 3.6)
l=list(mytuple)
# Print value at index 0
print(l[0])
# Print value at index 1
print(l[1])
# Print value at index -1
print(l[-1])
# Print all the values from index 0
print(tuple(l[0:]))
n=len(l)
k=int(len(l)-1)
# Print all the values except the last value
print(tuple(l[0:k]))
print(mytuple[::-1])

Q4. Need Solution
Q5. Need Solution
Q6.

d=input("data: ")
l=d.split(",")
t=tuple(l)
print("tuple:",t)
v=input("value: ")
if v in d:
	print("True")
else:
	print("False")

Q7.

# mytup = ('a', 'b', 'c', 'd')
# print("mytup =", mytup)

# # add elements to the mytup
# print("mytup =", mytup)
# print("mytup[4][1] = 4")

# # write your code here
# print("mytup =", mytup)
mytup = ('a', 'b', 'c', 'd')
print("mytup =", mytup)
l=list(mytup)
a=[1,2,3]
l.append(a)
t=tuple(l)
print("mytup =",t)
# add elements to the mytup
# print("mytup =", mytup)
print("mytup[4][1] = 4")
t[4][1]=4
print("mytup =",t)

Q8. Need Solution
Q9. Need Solution
Q10. Need Solution
Q11. Need Solution
Q12. Need Solution
Q13. Need Solution