Create a tuple with different data types and access elements:

SOLUTION .

# Taking dynamic input for a tuple
num = int(input("Enter an integer: "))
text = input("Enter a string: ")
decimal = float(input("Enter a floating-point number: "))
boolean = input("Enter a boolean value (True/False): ").strip().lower() == "true"

# Creating a tuple with different data types
data = (num, text, decimal, boolean)

# Accessing the second element
print("The second element is:", data[1])

Leave a Reply

Your email address will not be published. Required fields are marked *

sign up!

We’ll send you the hottest deals straight to your inbox so you’re always in on the best-kept software secrets.