In: Computer Science
Python
A program which prompts the user to enter an number which is a integer n and creates a tuple where the values are all numbers between 1 and n (both inclusive). Note: you can assume that the integer will always be > 1.
Input | Result |
---|---|
3 |
Enter an integer: 3 (1, 2, 3) |
CODE:
def createTuple(n):
#forming a list from 1 to n then casting it into a tuple
out = tuple([x for x in range(1,n+1)])
#returning the tuple
return out
#asking the user the value of n
n = int(input('Enter the value of n: '))
#calling the function
out = createTuple(n)
#printing the tuple
print('The output Tuple: ',out)
____________________________________________________
CODE IMAGES AND OUTPUT:
___________________________________________________
Feel free to ask any questions in the comments section
Thank You!