In this python tuple program, we will convert a given tuple of integers into a number.
Steps to solve the program
- Take a tuple of integers as input and create an empty string.
- Use a for loop to iterate over integers from the tuple.
- Add integers to the string after converting them to string datatype using str(), so that we can convert them into a single number.
- Print the output.
tup = (4,5,3,8)
str1 = ""
print("Original tuple: ",tup)
for val in tup:
str1 += str(val)
num = int(str1)
print("Integer: ",num)
Output :
Original tuple: (4, 5, 3, 8)
Integer: 4538